Unit testing with PHPUnit
2011-01-19This will likely be a multi-part series of posts, but I've been doing a lot of unit testing lately with PHPUnit and I feel I've learned several things worth sharing.
Debugging
Not everything you try in PHPUnit will work right away, and this is rarely PHPUnit's fault. When things to break, you have several options:
- Turn on
display_errors
and seterror_reporting
to a high value. This can be done in php.ini, the phpunit.xml file, as a command-line switch to the phpunit shell script, or directly in your bootstrap or test files using theini_set
anderror_reporting
functions. If your server configuration allows it, you can also set these values in .htaccess or .user.ini files. - Turn off processIsolation. This is set as a command-line flag or in phpunit.xml. The extra buffering and wrapping this directive uses (while generally a good idea) can sometimes hide the errors that cause your test suite to silently fail.