37

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/

Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81

7 Answers7

55

Add it as a library... in the project that you are editing add it to 'External Libraries'.

It should then be included.

Brian
  • 8,418
  • 2
  • 25
  • 32
  • 10
    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. – Shivaas Mar 22 '13 at 21:16
  • 1
    What about the .phar implementation of phpunit? UPDATE: I got around this on my mac by just using a homebrew install of the lib. – Jacob Thomason May 02 '14 at 04:26
  • 2
    You can just add the .phar file to the include path (you don't have to have the homebrew install as well). – Blair McMillan Jun 30 '14 at 02:15
  • 3
    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 Nov 12 '14 at 16:15
  • 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 – Pitt Oct 03 '16 at 21:16
  • Here is how to do that : https://www.jetbrains.com/help/phpstorm/2016.2/configuring-include-paths.html – paaacman Oct 19 '16 at 20:04
17

For me (Ubuntu 12.04) it was adding this folder as external library:

/usr/share/php/PHPUnit
jahller
  • 2,705
  • 1
  • 28
  • 30
16

For PHPStorm users, go to File -> Settings -> Project Settings ->PHP and add the path in there.

  • 5
    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 Nov 12 '14 at 16:14
11

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.

piersb
  • 609
  • 9
  • 22
  • 3
    Wow, thank you, I was wondering about this and have searched a few times for bugs. The ctrl space works for the time being. – Nick Jul 26 '16 at 15:49
4

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.

Timofey
  • 823
  • 1
  • 8
  • 26
E. Janssen
  • 41
  • 3
2

I have OSX, phpunit installed by homebrew and phpstorm 9.0

So how it works for me: open preferences or press cmd+, -> Languages&Frameworks -> PHP -> Include path -> add "/usr/local/Cellar/phpunit/4.7.6/libexec/"

avolkov
  • 31
  • 3
0

I have PHPStorm 2017.1.4 and my OS is Ubuntu 16.04. I already have phpunit.phar installed in my /usr/local/bin.

I will use ~/WORK/.. for the example paths but you should use the full path /home/myname/WORK/..

What I did is just go to a folder inside my home(like: ~/WORK/) and run:

composer require phpunit/phpunit

After composer was done downloading phpunit I added a new project include path to:

~/WORK/vendor/phpunit/phpunit/src

Now I have all of the PHPUnit autocompletion, I can jump into PHPUnit's source code directly and I can keep the PHPUnit's code updated with composer. I also removed the phpunit.phar from /usr/local/bin and replaced it with a link to ~/WORK/vendor/bin/phpunit