Here we go with a simple workaround to resolve a bad error that you can encounter with PHPUnit:
headers already sent and failure of the tests.
It happens, sometimes, that you have to work with the headers but your tests fail because PHPUnit sends headers before your application, and your
session_start() ( or similar ) call produces the error:
So you need to include a
session_start() before PHPUnit is executed.
This can be done with the latest releases of PHPUnit ( > 3.3 ) using a bootstrap file.
Talking to *buntu users: installing PHPUnit via package manager (or
apt-get) will install the
3.2.x version, not compatible with the bootstrapping stuff we need to do.
You can read an amazing tutorial on installing PHPUnit via pear on *buntu.
So after having succesfully installed PHPUnit ( today the lates package I could retrieve via PEAR was
3.4.9 )… let’s create this ( very silly ) bootstrap:
filling the file with a simple:
1 2 3
So now you can lunch your tests using this syntax:
If you use an XML config file you can use:
or, adding this
in the opening tag of the XML (
<phpunit> ), simply this:
as you normally do.