The definitive remote debug and unittest with PHPStorm guide: part 7
This post is part of the guide on how to setup your PHPStorm for remote debugging and unit testing. Click here for the beginning of this guide.
Debugging your PHPUnit tests
So, your unit-tests should be small, not doing much, taking one unit at a time to test. Overall, not much is around to actually debug. But on occasion, having the ability to actually stepping through the unit-tests can save you a headache or two!
Debugging your PHPUnit scripts isn’t really that hard. In fact, most of what we need to do, we already covered in the previous postings! Consider this: PHPUnit is nothing more than a PHP framework running from the command line interface. And since we already know how to debug applications from the CLI, it must be easy!
How about this:
- Set a breakpoint in a unit-test of choice.
- Run the unit-test suite (directly in phpstorm)
PHPStorm should break in your test and you will be able to step through your code. It MIGHT break on the first line of phpunit, and not directly your first breakpoint, if PHPStorm cannot find the mappings for phpunit. If you want to run your phpunits directly from the command line, don’t forget to add the XDEBUG_CONFIG flags for it as described in the debugging cli applications chapter.
Sadly, we’ve just ended the last chapter in our guide. By now, everything you need to get your phpstorm up and running with virtualized environments should be there: unittesting, code completion, cli and web debugging and even more. Hopefully, newer versions of phpstorm will allow us to make it just as easy to setup virtualized environments like we can now with local ones. But until then, hopefully our guide will help!