Unable to run unit tests in PHPStorm's IDE

11,948

Solution 1

PhpStorm uses wrapper/helper script when executing PHPUnit tests (for integration purposes: monitor execution progress, stack trace etc).

At the moment that helper script does not support PHPUnit 3.8 or 3.9 -- only 3.7 and below.

Corresponding ticket: http://youtrack.jetbrains.com/issue/WI-21666 -- watch it (star/vote/comment) to get notified when it will be resolved.

P.S.
This issue is now fixed and fix will be available in next public EAP build (newer than current 134.1456).

Solution 2

Another solution: Set

"phpunit/phpunit": "3.7"

in composer.json

and run

composer update 

Then the issue will be resolved.

this worked for me also...

IntelliJ IDEA won't run PHPUnit 4.0 tests

Solution 3

Some user named andriy komm added solution based on manual fixing of php plugin in IDE in ticket thread (http://youtrack.jetbrains.com/issue/WI-21666):

A workaround until it is fixed:

  1. go to /plugins/php/lib

  2. make a backup of php.jar

  3. Use whatever tool you have to open the file, usually zip or other compress tools or under ubuntu the file roller.

  4. Go to scripts/phpunit.php

  5. Modify it, searching for the "IDE_PHPUnit_Framework_TestListener" class and adding there the following line:

public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) {} 6. save the file and update the php.jar

Note 1: depending on OS and tool you use, you might have to unpack the .jar to modify and compress it back to jar again. Using file roller on ubuntu I could skip this step, edit the file and update the jar directly.

Editing the /tmp/ide-phpunit.php DOES not help, because it get overriden by the phpunit.php file, which I mentioned above.

Note 2: Also depending on the version, you might find the php.jar elsewhere:

Either here: Go to your users home directory (windows/linux) and search vor a hidden directory .Webide, while is a number depending on your phpstorm version (e. G. .Webide70)

Or here: I think earlier versions were named like .IntelliJIdea while is a number depending on your phpstorm version.

And there use the same path (/plugins/php/lib)

Worked for me (Windows 7, PHPStorm 7, #PS-133.982).

Share:
11,948
Ben
Author by

Ben

Updated on June 24, 2022

Comments

  • Ben
    Ben almost 2 years

    When I run vendor/bin/phpunit my tests all run successfully. However, when I right click on a tests file and click "Run tests" I end up seeing:

    /usr/local/bin/php -dxdebug.coverage_enable=1 /private/var/folders/bj/t2w187x158g7rgghctgknwb80000gn/T/ide-phpunit.php --coverage-clover /Users/bkuhl/Library/Caches/WebIde70/coverage/services$tests.coverage --no-configuration /Users/bkuhl/Projects/myproject/services/app/tests
    Testing started at 3:09 PM ...
    
    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 /private/var/folders/bj/t2w187x158g7rgghctgknwb80000gn/T/ide-phpunit.php on line 504
    PHP 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 /private/var/folders/bj/t2w187x158g7rgghctgknwb80000gn/T/ide-phpunit.php on line 504
    Call Stack:
        0.0008     340040   1. {main}() /private/var/folders/bj/t2w187x158g7rgghctgknwb80000gn/T/ide-phpunit.php:0
    
    PHP Stack trace:
    PHP   1. {main}() /private/var/folders/bj/t2w187x158g7rgghctgknwb80000gn/T/ide-phpunit.php:0
    
    Process finished with exit code 255
    

    I have PHPStorm configured to use path/to/vendor/autoload.php

    enter image description here I've temporarily changed the path of this directory for the purpose of this screenshot, but it is a perfectly valid path.

    Has anyone run into issues using PHPStorm's ability to run your tests?

    composer.json:

    "require-dev": {
        "way/generators": "dev-master",
        "way/laravel-test-helpers": "dev-master",
        "mockery/mockery": "*",
        "codeception/aspect-mock": "*",
        "phpunit/phpunit": "3.9.*@dev"
    },
    
  • Darien
    Darien over 10 years
    Unfortunately it still affects IntelliJ IDEA 12.1.6. If only I could override how it generates the temporary file...
  • CXJ
    CXJ almost 10 years
    I just ran into this with PhpStorm 7.1.3. PHPUnit is currently at 4.2.0! Guess I'll have to downgrade.
  • Mirouf
    Mirouf about 8 years
    I got the same problem with jenkins.. Thank you !