Blog

PhpStorm cause fatal error with PHPUnit runInSeparateProcess

If you try to run simple tests with the latest PHPUnit 4 version (v4.8.23) everything works without a problem. But for special situation like testing of published HTTP-Header, you need to run these tests in a separated process. Or you see warnings like Cannot modify header information - headers already sent by .... To use an own process for a unit test you need to add an @runInSeparateProcess annotation in front of your test. This approach should provide a solution for these kind of tests. But PhpStorm 9 doesn’t work with the newest PHPUnit 4 version and shows the following error on all tests with a separated process:

PHP Fatal error:  Uncaught Error: Class 'PHPUnit_Util_Configuration' not found in -:312
Stack trace:
#0 {main}
  thrown in - on line 312

A research on the web showed that I am not the only one, who have this problem, but it is a very rare problem. The only solution I could find was to use an older version of PHPUnit, but nobody knows with which PHPUnit version this feature is broken. I have tried a few different versions of PHPUnit and I could determine, that v4.8.10 is the latest version, where the feature of separated process is not broken in PhpStorm.

Changelog: PHPUnit v4.8.11
  • Merged #1885: Fixed handling of PHP configuration settings for process isolation
  • Fixed #1857: @covers and @uses should only take a single word
  • Fixed #1879: assertEqualXMLStructure() cannot compare nodes with an ID
  • Fixed #1898: @covers and @uses cannot be used for namespaced functions
  • Fixed #1901: –self-update updates to PHPUnit 5, even on PHP < 5.6

The changelogs for the next PHPUnit version shows that v4.8.11 includes a bugfix for process isolation. I didn’t checked these changed lines of this bugfix, but by description of this change it could caused this PHPUnit error. Another question is why the hell cause such a tiny change in PHPUnit a broken execution in PhpStorm. Furthermore a normal execution of PHPUnit by command line runs like charm and shows not a single error message. It must have do with the way how PhpStorm executes PHPUnit.

$ php /tmp/ide-phpunit.php --configuration /path/phpunit.xml.dist

You can see in the previous example that PHPStorm uses a wrapper for PHPUnit execution. This wrapper has various functionalities like PHPUnit loading, initialization and also overwrites a few classes for printing test results in a specific format. This wrapper for PHPUnit causes in my development environment especially with composer more problems then it solves.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *