Code coverage helps a lot in assessing the reach of your unit tests, particularly in complex functions that span multiple execution flows. Despite being a great tool I haven’t used it much at work, and that’s mostly because I’m not fond of having to generate reports like this locally (in my development machine), instead I always try to automate this kind of repetitive task and integrate it in our automation server (jenkins). The problem is that for budget and legacy (mostly budget) reasons our jenkins is running in a semi-production server, which means that we can’t install xdebug on it, and you need xdebug in order to generate phpunit code coverage reports. At least that’s what I thought.

Some time ago I discovered phpdbg, a PHP interactive debugguer. This RFC has a good summary of what exactly you can do with it. Anyway turns out that phpdbg doesn’t impact the performance of your server and you can use it to generate code coverage, which is great if you are on a situation where you can’t have xdebug installed.

Assuming that you have phpunit and phpdbg installed and that you already have some idea about to generate phpunit coverage reports, here’s how you do it with phpdbg:

phpdbg -qrr [phpunit bin path] --coverage-html [report folder] [target folder]

Is basically the same as with xdebug, but calling phpunit through phpdbg with the qrr flags.