Blog

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:

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.

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

Thx for the tip! I tried it and it works perfectly. I never thought, that PHPUnit has a problem to load the Composer-Autoloader in separated processes. But It make sense, because I have only definied the Autoloader as bootstrap file at phpunit.xml and the bootstrap file is only called once.