15

I am trying to use PHPUnit with PhpSTORM by loading it from autoloader file. But, as you can see in the below screenshot, PHPUnit version: is not installed, i am getting the same even if i choose other two options. i.e. Path to phpunit.phar and Load from include path(PEAR).

enter image description here

here is what i get when i run a test case: enter image description here

PhpUnit classes and code autocompletion is being detected but PhpStorm editor just fine.

Fshamri
  • 1,346
  • 4
  • 17
  • 32
  • Did you try pressing the refresh button ? Is that the right path to the project having PHPUnit installed ? – Steve Chamaillard Aug 05 '17 at 09:32
  • Yes, i pressed the refresh button many times. the path is correct. BTW, this problem is only in my MAC. in windows it works fine – Fshamri Aug 05 '17 at 09:57
  • First, you are several MAJOR versions behind with PHPUnit. you should be running 6.x with PHP v 7.x. Second, load it from the phar and life will be much easier. There is no reason to load it from an autoloader when you should be using a consistent version of PHPUnit throughout your application. – DrDamnit Aug 06 '17 at 17:49
  • Double check with a terminal that vendor autoload has phpunit at all. `$ ./vendor/bin/phpunit` from within your project directory has to work otherwise it's not installed via vendor. This is one way to verify. Additionally the `255` which is given as exit status shows that PHP has crashed, most likely a fatal error. Don't know MAMP much, but could be that there are two PHPUnit versions intermixed. E.g. one with global PEAR install and one in the project. This must not be visible from the version displayed, it could just be that you include older files. Error reporting and display to the max. – hakre Aug 08 '17 at 19:05

3 Answers3

25

If this happens and you see the red I with PHPUnit Version not installed then you probably get the message "Please select PHP Interpreter to load PHPUnit version" when you press the refresh button.

If you have the path to phpunit.phar set and your path the composer autoloader is fine, then it is possible that PHPStorm simply doesn't get what PHP exe file to use to load the PHPUnit.

You can then choose to add a Remote PHP Interpreter but you may also choose to add a local PHP Interpreter (for instance if you have XAMPP or WAMPP or LAMPP installed on your computer).

Press Ctrl+Alt+S and go to -> Languages & Frameworks -> PHP -> CLI Interpreter -> go for the button with the dots (or shift + enter) and there you can add an "Interpreter" by pressing the + button.

I added my own local interpreter xampp\php\php.exe Press apply and okay and go back to Languages & Frameworks -> PHP -> Test Frameworks and go for the refresh button. It should do some magic and then it will say PHPUnit version: 6.5 (or whichever you installed). I had my local (XAMPP) Apache server running.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Isolde
  • 626
  • 6
  • 12
2

For anyone running into this in 2020 and also if you have problem with Docker container mapping, Path Mapping stay same if you select your Project root in Docker container option:

Just add double slash at your host path: //, looks like this is bug in PHPStorm.

docker container PHPStorm config

PHPSTorm test framework config

KorbenDallas
  • 944
  • 9
  • 16
0

Try setup path to script without full path

vendor/autoload.php