How can I get IDE autocomplete for PHPUnit?
Solution 1
Add it as a library... in the project that you are editing add it to 'External Libraries'.
It should then be included.
Solution 2
For me (Ubuntu 12.04) it was adding this folder as external library:
/usr/share/php/PHPUnit
Solution 3
For PHPStorm users, go to File -> Settings -> Project Settings ->PHP and add the path in there.
Solution 4
PhpStorm 2016.2 introduces a feature which - in this case - is also a bug.
Autocompletion now no longer includes static methods as an option when in $this-> context. (https://blog.jetbrains.com/phpstorm/2016/07/completion-changes-in-phpstorm/#more-10425)
As phpunit tests are defined as static methods but called via $this->, autocomplete for phpunit is now effectively broken.
They've rolled back this change for phpunit in the next EAP (https://youtrack.jetbrains.com/issue/WI-32530).
Workaround until the next stable release: Press CTRL-Space twice; this will then show static methods in the autocomplete field.
Solution 5
You can add package phpunit/phpunit
to the require-dev
section of your composer.json file.
After running composer install
, PHPStorm will know about the PHPUnit classes.
Comments
-
Vitalii Zurian almost 2 years
I am using Symfony2, everything is installed, my tests work so good so far.
I'd like to get an autocompletion of PHPUnit's methods.
Symfony's
WebTestCase
class extends fromPHPUnit_Framework_TestCase
just like below:abstract class WebTestCase extends \PHPUnit_Framework_TestCase
The parent class is highlighted as not existing although.
How can I tell my IDE to use PHPUnit's library?
I am using PHPStorm
PHPUnit is available by path/Users/myUser/pear/share/pear/PHPUnit/
-
Shivaas about 11 yearsFYI, to get to your project settings on Mac, click on PhpStorm -> Preferences, click PHP (under project settings), and then on the right you can add paths to your include path.
-
Jacob Thomason about 10 yearsWhat about the .phar implementation of phpunit? UPDATE: I got around this on my mac by just using a homebrew install of the lib.
-
Blair McMillan almost 10 yearsYou can just add the .phar file to the include path (you don't have to have the homebrew install as well).
-
Loren over 9 yearsWith phpunit installed by homebrew, the path is /usr/local/opt/phpunit/libexec/ (this is a symlink so it will stay constant even with version changes)
-
Loren over 9 yearsWith phpunit installed by homebrew, the path is /usr/local/opt/phpunit/libexec/ (this is a symlink so it will stay constant even with version changes)
-
Maxim Pontyushenko over 8 yearsCould you add some details to your answer?
-
Czechnology almost 8 yearsThis worked nicely for me, adding the lib manually (as in other answers) didn't work out for me.
-
Czechnology almost 8 yearsMaxim: Just add e.g.
"phpunit/phpunit": "^5.4.6"
to the"require-dev"
section of yourcomposer.json
and runcomposer update
. -
piersb almost 8 yearsTried this on PhpStorm 2016.2. No joy. :(
-
Nick almost 8 yearsWow, thank you, I was wondering about this and have searched a few times for bugs. The ctrl space works for the time being.
-
Pitt over 7 yearsAs for those having a global composer install of phpUnit, add ~/.config/composer/vendor/phpunit to the path. And for those using PHPStorm 2016.2 checkout @piersb 's answer below
-
paaacman over 7 yearsHere is how to do that : jetbrains.com/help/phpstorm/2016.2/…