35

Cannot find PHPUnit in include path is the error message I get when I try to run my code in phpstorm.

In the PHP Settings, my PHP level language is 5.4 (traits, short array syntax, etc.) and interpreter is Name(5.4.7) where Name is user defined.

The error appears when I try to run the code and the exact message is this:

C:\xampp2\php\php.exe C:\Users\DELL\AppData\Local\Temp\ide-phpunit.php --no-configuration

C:\xampp2\htdocs\ft-website

Testing started at 2:34 PM ...

Process finished with exit code 1

Cannot find PHPUnit in include path (.;C:\xampp2\php\PEAR)`

3
  • You should do exactly as error message says: add the path where PHPUnit files are located to the include_path config variable in your php.ini Commented Aug 19, 2013 at 9:29
  • Is PHPUnit actually installed in C:\xampp2\php\PEAR? The best way to go would be to either install it there using PEAR, or adjust your PHP include path to a PHPUnit installation at another location. Commented Aug 19, 2013 at 9:30
  • I have a php\pear folder. I'm just going to go ahead and install using PEAR and see if that fixes it. Commented Aug 19, 2013 at 9:42

7 Answers 7

58

Just encountered this problem myself.

I'm unsure why it is unable to find PHPUnit in the include path (despite the fact that it is there, albeit in all lowercase).

I got around this by changing my IntelliJ Preferences for PHPUnit (under PHP --> PHPUnit). I changed the PHPUnit library settings to Use custom loader and then specified the path to the phpunit executable. On my mac, that was /usr/local/Cellar/php54/5.4.26/bin/phpunit.

UPDATE:

I just discovered that pear now installs PHPUnit as a phar named phpunit. It previously installed the PHPUnit source, which was really nice for reference and code completion in PHPStorm. I think that this is the reason things aren't working any longer with PHPStorm, because it's expecting a php executable and not a php archive.

So, I'm moving away from using pear to install PHPUnit, and I'm using composer instead. This bundles PHPUnit directly as a dependency of my project, which makes it more portable than a system dependency. You'll need to add vendor/phpunit/phpunit as a PHP include path in your PHPStorm preferences. This will serve two purposes:

  1. PHPStorm can find the phpunit executable now
  2. PHPStorm will index all the PHPUnit classes now, so you'll get auto-complete. Yay!

To do this, go to Languages and Frameworks in the PhpStorm settings. If you click on PHP, on the right you have your include paths

Sign up to request clarification or add additional context in comments.

3 Comments

sorry, how do I add vendor/phpunit/phpunit as a PHP include path? I'm unclear.
For drupal8 path will be /PATH/TO/DRUPAL/core/tests/bootstrap.php
When using Laravel Homestead, remeber not to use local interpreter, but remote one. For the first time you must add it in Languages & Frameworks -> PHP -> PHPUnit using green plus in upper left corner
25

I had this problem after adding PHPUnit via composer.

I fixed this by choosing use custom autoloader in Settings -> Languages and Frameworks -> PHP -> PHPUnit, then adding /vendor/autoload.php as the location of the custom autoloader.

2 Comments

Doesn't appear to be a relative path unfortunately. Don't know why I would have to correct this each time I work on a project.
I combined this with @Ben's answer above and now it works (using IntelliJ).
4

In addition to Ben's answer, in phpStorm 7.1.3 it works by specifying the phpunit.phar location under the "use custom loader" option, for example:

"Path to script: /usr/share/php/phpunit.phar"

1 Comment

Please add more description to your answer. It will help questioner in grasping more out of your answer.
4

This is the way to do it without using composer, and using your global phpunit.

  1. Phpunit now comes with a phar file. My path was /usr/local/Cellar/phpunit/5.0.0/libexec/phpunit-5.0.0.phar

enter image description here

  1. PhpStorm Preferences -> Path to phpunit.phar -> select the phpunit phar

enter image description here

  1. That's all, good stuff.

1 Comment

To get autocompletion, the directory containing the phar can be added as an include path. In the image above it would be /usr/local/Cellar/phpunit/5.0.0/libexec/.
2

I had this same problem for PHPStorm 2017 using Vagrant. First go to Settings -> Languages and Frameworks -> PHP and Add a remote interpreter, then go to Settings -> Languages and Frameworks -> PHP -> PHPUnit click the + on top and click by Remote Interpreter. If you're using Composer autoloader, then enter your full Vagrant path to your autoloader file.

3 Comments

I exactly needs this, but cannot make it work. If I run the test I still get "Cannot find PHPUnit in include path". I did what you wrote - so can you plz give some more detailed information on that?
Ok found my answer here: stackoverflow.com/questions/12814263/… - basically I had to do "Select Use custom loader and then enter the autoload.php" - so actually I just did not understood your answer fully ;-)
Glad my answer helped :)
0

For future readers, to fix the same issue when using PHPStorm + Vagrant + PHPUnit by defining path to the global phpunit.phar (not composer)

While the tests runned successfully, I was missing the code completion. I had confirmed that phpunit was in the PATH on my local machine, and to make sure, I had added /usr/local/bin to the PHP Include paths in PHP Settings. Still no code completion.

The reason: PHPstorm was looking for phpunit.phar, not just phpunit. To fix, on my local machine I established a symlink phpunit.phar pointing to phpunit:

$ cd /usr/local/bin/
$ sudo ln -s phpunit phpunit.phar

Then I reindexed the project, and code completion started working.

Comments

0

For those that are looking at it in 2020, starting from PHPStorm 2019 this is under:

Languages and Frameworks->PHP->Test Frameworks
  1. Choose to add a new library
  2. Select "PHPUnit"
  3. Select "Path to phpunit.phar" radio
  4. You'll have an automatic option to download PHPUnit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.