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:

  1. Set a breakpoint in a unit-test of choice.
  2. 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.

 

 

Conclusion

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!

  • […] Dutch Web Alliance has posted the seventh part of their series looking at getting remote debugging and unit testing working with PHPStorm, a […]

  • […] Dutch Web Alliance has posted the seventh part of their series looking at getting remote debugging and unit testing working with PHPStorm, a […]

  • […] Dutch Web Alliance has posted the seventh part of their series looking at getting remote debugging and unit testing working with PHPStorm, a […]

  • Joshua Thijssen is an all-round consultant and trainer. His daily work consists of maintaining code bases, working on different projects and helping other to achieve higher standards in both coding and thinking. He is author of the PHP|Architect book "Mastering the SPL library" and the Symfony Rainbow Series, founder of the Dutch Web Alliance and regular speaker at national and international conferences. Find him on twitter at @JayTaph, or read his personal blog at https://adayinthelifeof.nl

    Dutch Web Alliance