php-code-coverage
php-code-coverage copied to clipboard
Allow working with XDebug Code Coverage data with XDebug disabled
Q | A |
---|---|
php-code-coverage version | 9.2.24 |
PHP version | 8.2 |
Driver | Xdebug |
Xdebug version (if used) | 3 |
Installation Method | Composer |
Usage Method | other |
Hi,
I collect Xdebug Coverage data while running integration tests with PHPUnit + Selenium Hub inside a Docker machine. I then collect the code coverage data, merge the ones that belong to the same test and use PHP_Code_coverage to generate a report in clover and HTML.
This works great, with one caveat. The exported coverage files are sometimes several megabytes and merging them is very CPU and memory intensive.
Without XDebug, merging these takes a few seconds, with XDebug in Coverage mode this balloons to several minutes. In order to run it without xdebug I added this rather horrible shim:
defined('XDEBUG_FILTER_CODE_COVERAGE') || define('XDEBUG_FILTER_CODE_COVERAGE', 1);
defined('XDEBUG_PATH_INCLUDE') || define('XDEBUG_PATH_INCLUDE', 1);
if (!function_exists('xdebug_set_filter')) {
function xdebug_set_filter() {};
}
putenv('XDEBUG_MODE=coverage');
$coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$filter
);
putenv('XDEBUG_MODE=');
It does the job, but I wish I could just process the code-coverage data without the need to either move the merging of the data to an external process or having to resort to a hack like this. It should be rather simple to pass an argument to the selector or provide an environment flag that disables checking when it's not needed.
Thank you again for the amazing work <3