2

When testing with zend & phpunit. Header error show on console. I find the error:

Cannot modify header information - headers already sent by (output started at /usr/share/php/PHPUnit/Util/Printer.php:173)

I try to debug with the instructions in some topic Is there a way test STDERR output in PHPUnit? and PHPUnit output causing Zend_Session exceptions. But when use --stderr option, I can not find some output and report of testcase. This is the output on the console:

root@ubuntu:/home/boingonline/www/testunit# phpunit --stderr
PHPUnit 3.5.15 by Sebastian Bergmann.

root@ubuntu:/home/boingonline/www/testunit# 

Any ideas for this problem? Thanks for all answers.

Community
  • 1
  • 1
Phuong Vu
  • 527
  • 4
  • 16

1 Answers1

5

This is a bug in PHP. Whenever something is output (even on CLI, that's the problem), you cannot use header() calls anymore.

A workaround is to use process isolation for the test with @runInSeparateProcess.

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • The link to the PHPUnit documentation is broken: this is a working link for PHPUnit 9.5: [`@runInSeparateProcess`](https://phpunit.readthedocs.io/en/9.5/annotations.html?highlight=runInSeparateProcess#runinseparateprocess) – Matt Rice Feb 17 '22 at 14:15