How can I get IDE autocomplete for PHPUnit?

15,364

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.

Share:
15,364
Vitalii Zurian
Author by

Vitalii Zurian

#SOreadytohelp

Updated on June 03, 2022

Comments

  • Vitalii Zurian
    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 from PHPUnit_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
    Shivaas about 11 years
    FYI, 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
    Jacob Thomason about 10 years
    What 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
    Blair McMillan almost 10 years
    You can just add the .phar file to the include path (you don't have to have the homebrew install as well).
  • Loren
    Loren over 9 years
    With 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
    Loren over 9 years
    With 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
    Maxim Pontyushenko over 8 years
    Could you add some details to your answer?
  • Czechnology
    Czechnology almost 8 years
    This worked nicely for me, adding the lib manually (as in other answers) didn't work out for me.
  • Czechnology
    Czechnology almost 8 years
    Maxim: Just add e.g. "phpunit/phpunit": "^5.4.6" to the "require-dev" section of your composer.json and run composer update.
  • piersb
    piersb almost 8 years
    Tried this on PhpStorm 2016.2. No joy. :(
  • Nick
    Nick almost 8 years
    Wow, thank you, I was wondering about this and have searched a few times for bugs. The ctrl space works for the time being.
  • Pitt
    Pitt over 7 years
    As 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
    paaacman over 7 years
    Here is how to do that : jetbrains.com/help/phpstorm/2016.2/…