Note: this is not a duplicate question. I've seen some similar questions but I'm asking about unit testing.
I'm trying to write test cases using CakePHP 2.3.6 and having problems with the test cases that use header() function. The test runs with no problem from a browser, but from command line, I get the following error.
Cannot modify header information - headers already sent by (output started at /usr/share/pear/PHPUnit/Util/Printer.php:172)
The error is occurring at the following line in my code, for example.
header( 'Content-Type: application/json; charset=utf-8' );
For PHPUnit, @runInSeparateProcess can be used for avoiding this, but in CakePHP, it causes the following errors instead.
Notice: Constant TIME_START already defined in /app/lib/Cake/bootstrap.php on line 22
Notice: Constant CAKE already defined in /app/lib/Cake/bootstrap.php on line 48
Notice: Constant APPLIBS already defined in /app/lib/Cake/bootstrap.php on line 60
Notice: Constant SECOND already defined in /app/lib/Cake/basics.php on line 26
Notice: Constant MINUTE already defined in /app/lib/Cake/basics.php on line 27
and so on.
I'm stuck. Does anyone know how to handle this? Thanks a lot in advance.