Want to test PHP headers with PHPUnit? The issue is that PHPUnit will print a header to the screen and at that point you can’t add more headers. The work around is to run the test in an isolated process.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php class FooTest extends PHPUnit_Framework_TestCase { /** * @runInSeparateProcess */ public function testBar() { header('Location : http://foo.com'); } } |
The output will be like:
1 2 3 4 5 6 7 8 | $ phpunit FooTest.php PHPUnit 3.6.10 by Sebastian Bergmann. . Time: 1 second, Memory: 9.00Mb OK (1 test, 0 assertions) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.