gergelyrozsas / clover-diff
Clover Diff
0.1.0
2019-10-05 14:59 UTC
Requires
- php: ^7.2
- ext-simplexml: *
- psr/container: ^1.0
Requires (Dev)
- symfony/filesystem: ^4.2
Suggests
- symfony/filesystem: Required for the built in HTML report generator.
This package is auto-updated.
Last update: 2024-12-06 02:12:07 UTC
README
GergelyRozsas\CloverDiff
GergelyRozsas\CloverDiff is a library that provides processing and rendering functionality for comparing code coverage information from Clover XML files.
Installation
This library can be installed via Composer:
composer require gergelyrozsas/clover-diff
Using the GergelyRozsas\CloverDiff API
<?php use GergelyRozsas\CloverDiff\Factory; use GergelyRozsas\CloverDiff\Node\Iterator\RecursiveNodeIterator; $diff = Factory::getCloverDiff(); $report = $diff->compare([ '/path/to/clover1.xml', '/path/to/clover2.xml', ]); $iterator = new \RecursiveIteratorIterator( new RecursiveNodeIterator($report), \RecursiveIteratorIterator::SELF_FIRST ); /** @var \GergelyRozsas\CloverDiff\Node\NodeInterface $node */ foreach ($iterator as $node) { foreach ($node->getRevisions() as $revision) { echo \vsprintf("Coverage for %s on %s was %.2f%%.\n", [ \implode('/', $node->getPath()), \date('Y-m-d H:i:s', $revision->getTimestamp()), \round(100 * $revision->getCoveredElements() / $revision->getElements()), ]); } }
A build in HTML report generator can also be used if the symfony/filesystem library is installed.
<?php use GergelyRozsas\CloverDiff\Factory; $diff = Factory::getCloverDiff(); $report = $diff->compare([ '/path/to/clover1.xml', '/path/to/clover2.xml', ]); $generator = Factory::getHtmlReport(); $options = $generator->process($report); echo "The report was generated into the '{$options['target']}' directory.\n";
Credits
The concept for the HTML report was adopted from https://github.com/sebastianbergmann/php-code-coverage.