Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit via Composer and PhpStorm

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.

like image 886
shredding Avatar asked Sep 10 '25 03:09

shredding


1 Answers

@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:

  1. Go to File -> Settings -> PHP -> PHPUNIT.
  2. Select 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).
  3. Specify the default configuration file (this is usually phpunit.xml.dist from your project's app directory).

<code>PHP</code> -> <code>PHPUNIT</code>

That needs to be repeated per project, but the following needs to be done once.

You need to configure you defaults in PHPStorm correctly.

  1. Go to Run -> Edit Configurations... or just click the dropdown menu on the toolbar and select Edit Configurations....
  2. Go to Defaults -> PHPUnit
  3. Under Test Scope, select Defined in configuration file
  4. Make sure the Interpreter options textfield is empty
  5. Go to PHPUnit (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).

<code>Edit Configurations...</code>

like image 89
Adam Lynch Avatar answered Sep 12 '25 17:09

Adam Lynch