Behat and PHPUnit asserts in External Tool execution

I searched and found out how to run behat as an exteranl tool and it will work with the project as long as I throw exceptions and don't try to use PHPUnit asserts.

After considerable searching I have discovered the problem.

I am using a MacBook Pro running the lastest OS X and updates. I am using PHP 5.4.10 from the MAMP distribution for the project as installed from the DMG distribution. OS X comes with a default PHP installation installed in /usr/bin. In PhpStorm, I have set up installed the PHP version and I can build and run my project without problems. It is only when running behat as an external tool that I run into problems.

The difficulty is that PhpStorm places /usr/bin at the front of the PATH variable when running an external tool or running command line. The result is that when behat runs, it sets the php default library to /usr/lib and not to the version of PHP that I have set for the project. PHPUnit and a number of other utilities / extensions are all installed against the PHP 5.4.10 MAMP installation that is in the /Applications/MAMP/bin/php/php5.4.10/bin and lib directory. The result is that behat / PHP can't find the PHPUnit code that it requires. If I specifically put the absolute directory location of PHPUnit in the requires_once then it fails in PHPUnit because it is assuming that it is in the library path or a specific location relative to the project.

To confirm my suspicions, I used the terminal (command line) and made sure the PHP path was set to my desired version of PHP. Going to the base project directory and running behat shows that all the tests pass even using PHPUnit asserts.


NOTE: My setup is assuming that all my utilities are gloabl to the project and have been installed outside the project using composser. I haven't tried using composer withint the project to install PHPUnit, behat, and mink as project specific but since this is linked with the running of a PHP version, I suspect that some of the same problems will occur.

Have others experienced this problem when using different versions of PHP in PHPStorm.

6 comments

Problem solved. I had installed behat and its associated extensions in the users base directory. By installing using composer in the php version directory, behat can now find everything that it needs. It also looks now like PhpStorm is not adjusting the path so everthing is being found as expected.

0

This is proving inconsistent. Today, PhpStorm added the user/bin etc directories again and seems to be running the default install version of php rather than the MAMP installed version. Some more research is required. It seems to me that PhpStrom would want to ensure the path was consistent with the version of PHP selected for the project.

0

When running external commands from PhpStorm, it seems that the path used is based on the path defined when PhpStorm was started. If PhpStorm is started as an application on the Mac then this path is not set by any of the user profiles (still need to investigate how this path is defined). If PhpStorm is started from a terminal window then the path is defined by the .profile_bash defined path. The difference on my system is that the default path for an application includes /usr/bin ahead of the MAMP PHP version path. As a consequence the wrong version of PHP is run when I run external commands.

By using the $PhpExecutable$ as the program with /Applications/MAMP/bin/php/php5.4.10/bin/behat as the parameter behat runs as expected when running PhpStorm as an application. The thing is behat is marked as an executable so it can be run from the command line but if the command line context isn't set with the paths for the correct php executable then it fails.

0

When running external commands from PhpStorm, it seems that the path used is based on the path defined when PhpStorm was started. If PhpStorm is started as an application on the Mac then this path is not set by any of the user profiles (still need to investigate how this path is defined). If PhpStorm is started from a terminal window then the path is defined by the .profile_bash defined path. The difference on my system is that the default path for an application doesn't includes /usr/bin ahead of the MAMP PHP version path. As a consequence the wrong version of PHP is run when I run external commands.

By using the $PhpExecutable$ with /Applications/MAMP/bin/php/php5.4.10/bin/behat as the parameter behat runs as expected when running PhpStorm as an application. The thing is behat is marked as an executable so it can be run from the command line but if the command line context isn't set with the paths for the correct php executable then it fails.

This is the external command configuration that I am now using successfully.

0

Hi there,

It's the way how Mac OS works (you have different values of PATH environment when running from Terminal and PhpStorm).

Check this link: http://stackoverflow.com/questions/18193043/error-using-phpstorms-sass-file-watcher/18209348#18209348

0

Thanks. I hand't noticed the environment variables. I do find it strange that PhpStorm doesn't setup the environment for external commands and execution to match what has been defined in the project.

0

Please sign in to leave a comment.