Code Coverage with PHPUnit

Dave picture Dave · Apr 21, 2011 · Viewed 10.4k times · Source

I am running into an issue while attempting to determine code coverage on our site. I have PHPUnit generating a html code coverage report while running our unit tests on our three apps. We have a public app, an admin app, and a reporting app. I'd like to somehow combine these into one code coverage report since the apps share code.

It seems that the code coverage is only calculating coverage on the files that the tests "touch", so completely untested files aren't being used in the calculation. Does anyone know how to pull these unused files into the calculation? Is there a way to tell the coverage generator to calculate using certain directories so that it pulls in the files that aren't touched? I have a whitelist set up in the config file for phpunit set to the root of our project. All comments, answers, and bits of advice are welcome.

Answer

edorian picture edorian · Apr 21, 2011

If you have set up a <whitelist> in your phpunit.xml configuration file you should see all the not covered files. It might an issue with the pathes, try absolute ones to see that it creates 0% coverage for some files and then make the relative pathses work.

For combining the coverage there is not much you can to with phpunit that i know of. You could combine the coverage results (PHPUnit_Coverage package) by hand and then figure out how to render them but you'd need to do that by hand. At least i don't know of any project/tool/way that does that for you.

The easiest way would be to run all your 3 testsuites in one phpunit run and have it generate the code coverage for the parts you are about.