IntelliJ IDEA won't run PHPUnit 4.0 tests

Darien

Sometimes IntelliJ IDEA has problems running, debugging, or showing code-coverage for PHPUnit tests. This can occur when the classes it generates are not compatible with the version of PHPUnit you have.

In my case, it's IntelliJ IDEA 12.1.6 versus PHPUnit 4.0.14, which always fails with this message:

/usr/bin/php /tmp/ide-phpunit.php --configuration /home/username/Documents/stuff/phpunit.xml.dist
Testing started at 5:32 PM ...
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 /tmp/ide-phpunit.php on line 496
PHP Stack trace:
PHP   1. {main}() /tmp/ide-phpunit.php:0

Process finished with exit code 255

The code it is generating in /tmp/ide-phpunit.php does not contain a new method required by PHPUnit 4.x.

Things which I've tried that don't work:

  • Fixing the file manually and marking it read-only causes IntelliJ to stop and complain that it cannot replace the file.
  • Setting up a "run-before" command to automatically patch the file is insufficient, because it doesn't seem to work for debugging nor code-coverage, only regular runs.
Darien

The best solution I've found is to patch your IntelliJ installation with a manual fix. These instructions assume Linux paths, but the same basic process should be possible on Windows.

Find the JAR

First, find the php.jar file in your IntelliJ installation. JAR files are a kind of ZIP file, you can open (and modify) both of them with the same tools. On my system, it was present at:

/home/username/.IntelliJIdea12/config/plugins/php/lib/php.jar

Make a backup of php.jar, since we're going to edit it.

Extract the template

Using a popular ZIP-file tool (like 7-Zip) open php.jar, and find the compresesd file inside called:

scripts/phpunit.php

Extract this file to a temporary location where you can edit it.

Add the method to the template

Inside the file, we need to find the class IDE_PHPUnit_Framework_TestListener, which in my case is around line 303. On that class, we need to add a new method:

public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}

Save the file when you are done.

Update the JAR with the new template

Now overwrite scripts/phpunit.php inside the JAR with your new version. Depending on your ZIP tool, this might have been as easy as double-clicking the file to open it, saving your changes, and clicking a confirmation prompt, but it depends on what you're using.

Restart IntelliJ

Now you should be done! Running, debugging, or generating code-coverage data with PHPUnit should be just a convenient click of a button.

Note that if you update your PHP plugin, it will probably overwrite the fix and you'll need to re-apply it again.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't run and debug groovy tests under intellij idea

From Dev

How run all tests for class in Intellij Idea?

From Dev

How run all tests for class in Intellij Idea?

From Dev

Sbt won't run ScalaTest tests

From Java

Jetpack compose: Android Tests won't run

From Dev

How to run all Specs2 tests under IntelliJ IDEA?

From Dev

Make IntelliJ IDEA run JUnit tests with -parameters javac option

From Dev

How run main class or tests in IntelliJ IDEA 2018.2.1 (Ultimate Edition)

From Dev

Can't run phpunit tests from command line

From Dev

IntelliJ IDEA won't stop on assertions in debug mode

From Dev

IntelliJ IDEA Won't Load - Stuck on Splash Screen

From Dev

Intellij idea won't recognize import of local class in python 3

From Dev

Why doesn't IntelliJ Idea recognize my Spek tests?

From Dev

Grails 2.3 Migration Scripts Won't Run During Integration Tests

From Dev

nunit-console won't run any tests

From Dev

Maven won't run JUnit5 tests

From Dev

Vim Fireplace with nREPL on docker won't run tests

From Dev

Python - aiohttp - Why won't my tests run?

From Dev

IntelliJ cucumber-jvm plugin doesn't run tests

From Dev

IntelliJ cucumber-jvm plugin doesn't run tests

From Dev

Intellij IDEA Doesn't See Tests (java.lang.Exception: No tests found in class)

From Dev

How to run tests on every code change in IntelliJ IDEA from Scala sbt project?

From Dev

How can I run mocha tests remotely on IntelliJ IDEA 13 (or WebStorm)?

From Dev

Intellij IDEA - run all unit tests before launching the application with a single click

From Dev

Why setInterval (->...) ,0 won't run as I expected?

From Dev

Why can't I step through PHPunit tests with XDebug when I run them from the command line?

From Dev

Specify a Group of PHPUnit Tests to Run in Seperate Processes

From Dev

PHPUnit: How to run tests from browser?

From Dev

Can't type/delete in IntelliJ Idea, OSX El Capitan 4

Related Related

  1. 1

    Can't run and debug groovy tests under intellij idea

  2. 2

    How run all tests for class in Intellij Idea?

  3. 3

    How run all tests for class in Intellij Idea?

  4. 4

    Sbt won't run ScalaTest tests

  5. 5

    Jetpack compose: Android Tests won't run

  6. 6

    How to run all Specs2 tests under IntelliJ IDEA?

  7. 7

    Make IntelliJ IDEA run JUnit tests with -parameters javac option

  8. 8

    How run main class or tests in IntelliJ IDEA 2018.2.1 (Ultimate Edition)

  9. 9

    Can't run phpunit tests from command line

  10. 10

    IntelliJ IDEA won't stop on assertions in debug mode

  11. 11

    IntelliJ IDEA Won't Load - Stuck on Splash Screen

  12. 12

    Intellij idea won't recognize import of local class in python 3

  13. 13

    Why doesn't IntelliJ Idea recognize my Spek tests?

  14. 14

    Grails 2.3 Migration Scripts Won't Run During Integration Tests

  15. 15

    nunit-console won't run any tests

  16. 16

    Maven won't run JUnit5 tests

  17. 17

    Vim Fireplace with nREPL on docker won't run tests

  18. 18

    Python - aiohttp - Why won't my tests run?

  19. 19

    IntelliJ cucumber-jvm plugin doesn't run tests

  20. 20

    IntelliJ cucumber-jvm plugin doesn't run tests

  21. 21

    Intellij IDEA Doesn't See Tests (java.lang.Exception: No tests found in class)

  22. 22

    How to run tests on every code change in IntelliJ IDEA from Scala sbt project?

  23. 23

    How can I run mocha tests remotely on IntelliJ IDEA 13 (or WebStorm)?

  24. 24

    Intellij IDEA - run all unit tests before launching the application with a single click

  25. 25

    Why setInterval (->...) ,0 won't run as I expected?

  26. 26

    Why can't I step through PHPunit tests with XDebug when I run them from the command line?

  27. 27

    Specify a Group of PHPUnit Tests to Run in Seperate Processes

  28. 28

    PHPUnit: How to run tests from browser?

  29. 29

    Can't type/delete in IntelliJ Idea, OSX El Capitan 4

HotTag

Archive