The definitive remote debug and unittest with PHPStorm guide: part 5

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.

Remote code coverage

There is a nifty little plugin that allows you to instantly see your code coverage inside your code. This plugin is called “PHPUnit code coverage” and should be installed in the plugins configuration like all other plugins you install.

After a mandatory restart :(, you’ll get a PHPUnit Coverage tab inside your project configuration which allows you to setup all things needed for coverage.

coverage config

 

Clover XML location: your coverage file. Not yet available, and i’ll talk a bit later on how to create this file. Leave blank for now.

Use coverage suite: Just check this.

Colors: I’ve changed the colors to a more soft green and soft red. The standard colors are REALLY bright and in the end are hurting your eyes.

Highlight: you can choose if you want to see the code coverage on the whole line, or just in the sidebar. Because there is already soo much clutter in the sidebar (notes, errors, warnings, revision control), i just highlight the lines.

Path translation: enable this

Local directory: somehow this module doesn’t really use the path mappings from our server and we must set our path mappings here again. As the same with all path mappings: try and set the lowest directory, in our case /Volumes/www/myproject.

Remote directory: the other side of the path mapping: /wwwroot/myproject.

There isn’t much to configure and the plugin automatically detects new changes in the code coverage and updates your files accordingly.

Creating a clover file

Code coverage can be visualized with code coverage data which is normally stored in a so-called clover file. This file is automatically created by PHPUnit / XDebug when running your unit tests.

It’s actually quite easy if you already do unit testing. Change your phpunit.xml(.dist) and add the following:

This will generate a clover file inside the root of your project called .coverage.xml. It might be wise to ignore this file inside your .gitignore and this is the file you need to select inside the phpunit code coverage configuration.

At this point, whenever you rerun your PHPUnit tests, the .coverage.xml will be automatically updated and your code coverage will be displayed .

coverage screenshot

When running your PHPUnit tests (either from PHPStorm, or outside), the clover file will be updated, and your code will be annotated correctly. But sometimes the coverage isn’t updated or displayed properly. Normally a reopen of the file will work. When using horizontal or vertical tabs and have the same file open in both tabs, it will sometimes not update all the files.

 

 

That’s it. Fast and easy. In the next part, we will discuss on how to debug your command line applications!

  • […] Next time we do something fairly simple: adding some code coverage information! […]

  • […] Dutch Web Alliance has posted the fifth part (of seven) of their series looking at configuring the PHPStorm IDE to remotely debug and run your […]

  • […] Dutch Web Alliance has posted the fifth part (of seven) of their series looking at configuring the PHPStorm IDE to remotely debug and run your […]

  • 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