sebastianbergmann / phpcov

TextUI frontend for php-code-coverage
BSD 3-Clause "New" or "Revised" License
223 stars 58 forks source link

Support raw (JSON) from xdebug_get_code_coverage #111

Closed meeuw closed 2 years ago

meeuw commented 2 years ago

Before this patch only the .cov file format was supported, add support from .json files collected by serializing the output from xdebug_get_code_coverage.

Also allow a rewrite of the source code paths because it might be colected from a different environment (ie. bind mounts in container).

This could be useful if you want to collect coverage by only using xdebug (I'd like to use this to check/improve the coverage of integration tests):

php.ini:

auto_prepend_file = "prepend.php"
auto_append_file = "append.php"

prepend.php:

<?php
xdebug_start_code_coverage();

append.php:

<?php
$filename = uniqid();
file_put_contents("/var/www/html/coverage/$filename.json", json_encode(xdebug_get_code_coverage()));

It might make sense to add XdebugFileDriver to php-code-coverage, let me know if you'd like me to create a PR for that.

sebastianbergmann commented 2 years ago

Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it because I do not want code coverage driver specific code in this tool.

I think it would make sense to add functionality in php-code-coverage to serialize that component's object graph to JSON (and vice versa).