I run a couple of different PHPUnit test suits and for each of them, a coverage file is generated, like:
vendor/bin/phpunit -c phpunit-no-db.xml --coverage-php ./test/coverage/cov_files/NO_DB.cov
Afterwards all these coverage files are merged using php-cov to generate a clover file (XML):
/home/backbone/.local/bin/phpcov merge --clover ./test/coverage/clover.xml ./test/coverage/cov_files
This clover file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1661852015">
<project timestamp="1661852015">
<file name="/var/www/html/src/App/Console/CronjobRunnerCommand.php">
<class name="App\Console\CronjobRunnerCommand" namespace="global">
<metrics complexity="3" methods="3" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="4" coveredstatements="0" elements="7" coveredelements="0"/>
</class>
<line num="18" type="method" name="__construct" visibility="public" complexity="1" crap="2" count="0"/>
<line num="20" type="stmt" count="0"/>
<line num="22" type="stmt" count="0"/>
<line num="25" type="method" name="configure" visibility="protected" complexity="1" crap="2" count="0"/>
<line num="27" type="stmt" count="0"/>
<line num="30" type="method" name="execute" visibility="protected" complexity="1" crap="2" count="0"/>
<line num="32" type="stmt" count="0"/>
<metrics loc="35" ncloc="35" classes="1" methods="3" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="4" coveredstatements="0" elements="7" coveredelements="0"/>
</file>
...
My question: How to view this clover file in a readable way (like in a browser or as readable console output)?
What I tried so far:
- https://github.com/sebastianbergmann/phpcov doesn't seem to have this functionality
- https://github.com/sebastianbergmann/php-code-coverage is not very good documented, so I didn't come far
- I tried OpenClover's commandline tools, but it's documentation says, it needs a clover**.db** (for HTML: https://openclover.org/doc/manual/latest/commandline--htmlreporter.html). Not sure how to generate it.
- https://github.com/daison12006013/clover-coverage-to-html seems to allow transforming a Clover XML file to HTML, but it only runs on PHP 7.x, but my project is on PHP 8.1.
- If possible I don't want to install an IDE like JetBrains just to view clover.xml (https://youtrack.jetbrains.com/issue/WI-64063/Show-coverage-based-on-existing-cloverxml-instead-of-generating-IDE-coverage-file)
- except there is a viewer for Visual Studio Code (which I use), but I already checked, there is none available
Note: I am new to the Clover-world and may be a bit confused about file types etc.
I found it myself, after diving into the code of phpcov. The trick is to add
htmlargument in themergecommand. Badly documented.For completeness: Assume you run a a couple of PHPUnit test suits and each generates a Clover XML report like:
After they finished, run
phpcov mergeusinghtmlargument:It will generate HTML report in
./html-report. Voila!