PHP Unit is a very handy tool used to run PHP unit tests, useful for flagging up broken PHP scripts. We use PHP unit because we tend to break things… and naturally we are also probably going to break our test scripts too.
How to debug PHP Unit
By adding two lines of code to your phpunit.xml config file you can easily debug your PHP test scripts too;
- First, open phpunit.xml – it’ll probably be in the route of your application.
- Then look for the <php></php> tags in your config file (If they are not there just add them before the closing </phpunit> tag.
- In order to turn on error reporting, you’ll need to add/ alter the ‘display_errors’ ini setting, ensuring the value is set to true.
<ini name="display_errors" value="true"/>
- And that’s all there is to it really, if you are running a lot of tests or running some complex code you might also need to increase PHP’s memory limit.
<?xml version="1.0" encoding="UTF-8"?> <phpunit> ... <php> <ini name="display_errors" value="true"/> <ini name="memory_limit" value="100M"/> </php> </phpunit>