gergelyrozsas/clover-diff

0.1.0 2019-10-05 14:59 UTC

This package is auto-updated.

Last update: 2024-12-06 02:12:07 UTC


README

Latest Stable Version Build Status Code Coverage

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.