Version of PHPUnit in "Run/Debug"

PHPStorm 7

When I run a PHPUnit test by clicking on a green arrow icon near the "Run/Debug configuration" then the version is PHPUnit 3.7.21. And there are errors (e.g. Call to undefined method PHPUnit_Framework_TestResult :: deprecatedFeaturesCount). When I run the test directly from Terminal window by just typing "phpunit", then the version is PHPUnit 4.8.21 and all is fine. Is it possible to change the PHPUnit version that is called from the "Run/Debug" icon?

11 comments
Comment actions Permalink

Hi,

The unwanted version might have been taken from 'File | Settings | Languages & Frameworks | PHP', 'Include path'.
Anyways, you can configure how exactly you want to supply PHPUnit:
https://www.jetbrains.com/phpstorm/help/enabling-phpunit-support.html

0
Comment actions Permalink

I still can't get it working after trying the following methods described here:

Method 1) PHPUnit Library -> Use custom loader

I have the custom loader path set to C:\Users\User1\AppData\Roaming\Composer\vendor\autoload.php. This path leads to phpunit installed as global composer dependency and has version 4.8.23.

With this setting, when I click the green arrow to run a single test, the following output appears:

I:\xampp\php\php.exe C:\Users\User1\AppData\Local\Temp\ide-phpunit.php --configuration I:\xampp\htdocs\apps\laravel\phpunit.xml --filter ... (my test here)
Testing started at 09:32 ...

Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest) in C:\Users\User1\AppData\Local\Temp\ide-phpunit.php on line 504

Call Stack:
    0.0030     209672   1. {main}() C:\Users\User1\AppData\Local\Temp\ide-phpunit.php:0

Process finished with exit code 255

So in this case, PHPUnit dosn't work at all, probably because it runs C:\Users\User1\AppData\Local\Temp\ide-phpunit.php instead of using the composer autoload.php.

 

Method 2) PHPUnit Library -> Path to phpunit.phar

I downloaded phpunit.phar to directory I:\xampp\phpunit-phar\phpunit.phar and set the "Path to phpunit.phar" to this file.

With this setting, when I click the green arrow to run a single test, the following output appears:

I:\xampp\php\php.exe C:\Users\User1\AppData\Local\Temp\ide-phpunit.php --configuration I:\xampp\htdocs\apps\laravel\phpunit.xml --filter ... (my test here)
Testing started at 09:37 ...
PHPUnit 3.7.21 by Sebastian Bergmann.

So in this case, it works as before, with version 3.7.21 instead of 4.8.23. It also uses the C:\Users\User1\AppData\Local\Temp\ide-phpunit.php file. Deleting this file has no effect because it is re-created on each run.

I didn't test the third method which requires adding include path to PEAR (in my settings the include path is empty), but I think one of the other methods should work.

As I mentioned before, running tests directly from console is fine and uses the recently installed version 4.8.23.

Let me know how to get it working with either of the two methods (preferably composer).

 

 

 

 

0
Comment actions Permalink

Is someone able to help me?

0
Comment actions Permalink

We'll review that soon and chase an update for you. Thanks!

0
Comment actions Permalink

Could you please attach a screenshot of Run > Edit configurations.. > settings of your PhpUnit config?

0
Comment actions Permalink

Any chance you could update to PhpStorm version 10 and retry the same?

0
Comment actions Permalink

I tested this existing project in PHPStorm 10.0.1 (all user settings seem to be automatically taken from version 7, I didn't need to configure anything) and it's basically the same:

  • when running the test by pressing the green arrow, the output in Run panel says PHPUnit 3.7.21
  • when running the test from PHPStorm Terminal panel, the output says PHPUnit 4.8.21

[Edit] There are some minor differences, in the Terminal panel in PHPStorm 10 the version is 4.8.21 and in PHPStorm 7 it's 4.8.23 (perhaps because I made the upgrade of phpunit as mentioned in previous post in PHPStorm 7, but not in 10; for me this difference is irrelevant).

0
Comment actions Permalink

On your second run ( > Method 2) PHPUnit Library -> Path to phpunit.phar ) the output differs from mine:

C:\...\php\php.exe C:\...\phpunit\phpunit-5.2.9.phar --no-configuration C:\projectdir --teamcity

Testing started at 2:46 PM ...

PHPUnit 5.2.9 by Sebastian Bergmann and contributors.

Time: 125 ms, Memory: 8.00Mb
No tests executed!
Process finished with exit code 0



Could you please try to re-point PHPUnit to .phar file once again?

 

Thanks!

0
Comment actions Permalink

When I opened the PHPUnit settings in PHPStorm 10 and re-pointed the phar file, now it's ok (perhaps this setting was not imported automatically from version 7).

So the problem only appears in PHPStorm 7 and it seems that it doesn't load this phar file, although the setting is set correctly. Is it possible to fix in this version? (I can only evaluate version 10)

 

0
Comment actions Permalink

Most likely not, unfortunately. It's a common practice to implement fixes only for current or previous release versions.

0

Please sign in to leave a comment.