I am trying to generate an HTML Code Coverage report for a running PHP application. My goal is profile the application with XDebug while I run my functional tests to determine the code coverage of my functional test suite.
I can measure the code coverage for my unit tests via phpunit (which uses the php-code-coverage API to profile each unit test individually, then aggregates it into a code coverage report). And because these tools are built on top of xdebug I'm hoping that there is a way to take the output file from the XDebug profiler and generate an HTML report.
Here's what I have so far:
I am able to generate a cachegrind.out file by adding the following configuration in php.ini:
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=/var/log/xdebug_profiler
xdebug.profiler_output_name=cachegrind.out
xdebug.profiler_append=1
xdebug.coverage_enable=1
Then running my functional tests with the XDebug Helper Chrome extension in "PROFILE" mode. This adds XDEBUG_PROFILE to the cookie field of the HTTP requests which in turn triggers the profiler in the PHP application. (Alternatively, you could just turn on the profiler on for all requests with xdebug.profiler_enable=1)
The problem I have is transforming the output file (cachegrind.out) into the same kind of html report that is provided by phpunit. I can the profiler output using kcachegrind, but that application doesn't have a way to export a code coverage report, let alone specify included/excluded files.
I've also looked into the phpcov command line tool, but while it supports serialized PHP_CodeCoverage objects, it doesn't work with XDebug cachegrind files.
I am hoping that I can write some PHP that imports the XDebug profiler output file (cachegrind.out) into a PHP_CodeCoverage object and then following the example in the PHPUnit source code to make an HTML report. Does anyone have any experience profiling a running PHP application in this way? Is there an easier way to go about doing it?
I'd like to avoid using the PHP_CodeCoverage directly in my PHP application source code if possible.