Reputation: 5591
I'm now trying for hours to setup PhpStorm for unit testing. Whatever I do, I get this
Process finished with exit code 1
Cannot find PHPUnit in include path ...
PHPUnit is (via command line) accessible from anywhere; I've set the correct include path and have added PHPUnit to the external libraries. No chance.
Is it possible at all or does it only work with installations via PEAR? I've worked through all related questions here, am on Mac and PHPUnit is running smoothly via CLI.
Upvotes: 25
Views: 27470
Reputation: 1712
Possibly helpful for others.. PHPStorm successfully found my local PHPUnit via Composer, but am prompted with "Cannot find autoloader script at 'vendor/autoload.php'" and am unable to run my tests.
Fixed this by using the absolute path, e.g. /Users/Me/my-project/vendor/autoload.php
Upvotes: 0
Reputation: 1013
Patrick Visma posted the solution on http://youtrack.jetbrains.com/issue/WI-13429:
Edit the configuration for your phpunit.xml in PHPStorm, and set the Interpreter options like this:
-d auto_prepend_file=/path/to/vendor/autoload.php
Upvotes: 24
Reputation: 21
I want to add that current version of PHPStorm (7.1) works well only with the previous version of PHPUnit (3.7). And it fails to work with 4.0 and above. If you have downloaded phpunit.phar from http://phpunit.de, you can point PHPStorm to it via Settings => PHP => PHPUnit => Path to phpunit.phar
Upvotes: 2
Reputation: 4384
I have found that if I have all of my in the "Test" directory, and a test suite defined in a configuration file "Test/phpunit.xml"; I can simply setup a "Run Configuration" like so:
Phpstorm Run|Configuration dialog
Upvotes: 1
Reputation: 3369
@aderuwe's answer works but that config isn't scoped per project, it's for all projects. Since PHPStorm 6 (actually even EAP version PS-126.260
) you can do the following:
File
-> Settings
-> PHP
-> PHPUNIT
.Use custom loader
and then enter the autoload.php
file from your projects vendor directory. This autoloader will autoload all the dependencies managed by Composer (including PHPUnit).phpunit.xml.dist
from your project's app
directory).That needs to be repeated per project, but the following needs to be done once.
You need to configure you defaults in PHPStorm correctly.
Run
-> Edit Configurations...
or just click the dropdown menu on the toolbar and select Edit Configurations...
.Defaults
-> PHPUnit
Test Scope
, select Defined in configuration file
Interpreter options
textfield is emptyPHPUnit
(above Defaults
) and delete any entry under it (so that next time you a test on a particular file, etc. it'll set up a new one but using the new default).Upvotes: 62
Reputation: 38961
PHPStorm has a custom PHPUnit runner script ( ide-phpunit.php
) that it uses internally to deal with different versions of PHPUnit and to do the IDE integration and that is just relying on the include path and the PEAR
folder layout.
To do that it executes:
public static function checkIncludePath()
{
//check include path
$PHPUnitParentDirectory = self::getPHPUnitParentDirectory();
if (is_null($PHPUnitParentDirectory)) {
echo "Cannot find PHPUnit in include path (" . ini_get('include_path') . ")";
exit(IDE_PHPUnit_Loader::FAILURE_EXIT);
}
}
/**
* @return null | string
*/
private static function getPHPUnitParentDirectory()
{
$pathArray = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($pathArray as $path)
{
if (file_exists($path . DIRECTORY_SEPARATOR . 'PHPUnit/')) {
return $path;
}
}
return null;
}
You could just install it via composer and add it as a normal executable (ant/phing/native task) but you will loose all the shiny features PHPStorm offers like the progress bar, jumping to a failing test and the code coverage support.
So from the code you can tell taht you need to add a folder called named PHPUnit
to one of the places in your include path. Adding vendor might help there but keep in mind it needs to match case when doing so.
Until PHPStorm supports using PHPUnit from composer or a phar I don't think you will get better integration ( http://youtrack.jetbrains.com/issue/WI-13429
) with using it from pear but hacking your include path might work out.
The PHPStorm guys did some updates on the runner for 3.7 and are usually quite responsive to changes in PHPUnit :)
Upvotes: 1
Reputation: 42036
I would guess PhpStorm relies on finding PHPUnit in the include_path of php.ini itself, not of your project.
You can try adding your local project's vendor/bin directory to php.ini's include_path, but ultimately this seems like PhpStorm might benefit from supporting composer installs and run the phpunit of the project itself if it's available. There actually is an issue opened on their tracker so I would recommend you login there and upvote it: http://youtrack.jetbrains.com/issue/WI-13429
Upvotes: 5