Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headers already sent running unit tests in PHPStorm

I'm trying to use the integrated method of running phpunit tests within PHPStorm and having some issues getting it to work.

PHP: 5.6.10
PHPUnit: 4.5.1
PHPStorm: 8.0.3

Thanks to https://stackoverflow.com/a/30345501/1636594 I learned that I had to downgrade my phpunit version to < 4.6.

Finding https://stackoverflow.com/a/25903332/1636594 I tried both @runInSeparateProcess notation and strerr="false|true" in my configuration. With process isolation, I saw the same issue as this user (basically phpunit --help instead of each test in isolation). With stderr="false|true" I get the same either way (Cannot modify header information... blah blah).

The tests run fine without process isolation or stderr set to either one of true or false, both give successful passing tests. Screenshot of tests passing in terminal, failing in integrated runner

For now I'm obviously just running my tests in the terminal, but I would really like to be able to use the coverage feature but its basically useless for any line of code after a header call.

like image 758
Derokorian Avatar asked Jul 02 '15 04:07

Derokorian


1 Answers

I had same problem. When I try to run any of the codeception tests (specifically for Yii2) with the built-in PHPStorm tools, I get the message:

session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

I didn’t reach a long time, but yesterday after midnight dances with universal tambourines I found out literally the following:

PHPStorm (jetBrains for Google) uses the Codeception Framework plugin to place the file:

C:/Users/dev/AppData/Local/Temp/ide-codeception_before_24.php:405

from which, using the printEvent method, logs to the console via Printer::write():

vendor/phpunit/phpunit/src/Util/Printer.php:99

how to fix it nicely, I did not find, so "here is our answer to Chamberlain!": we write ob_start() in tests/_bootstrap.php:

<?php
require_once __DIR__. '/../vendor/yiisoft/yii2/Yii.php';
require_once __DIR__. '/ .. / vendor / autoload.php';

ob_start();

the buffer is flushed to the console automatically at the end of the tests. We get the following:

Example of running codeception run tests functional

like image 120
Ivan Kryazhev Avatar answered Sep 23 '22 10:09

Ivan Kryazhev