Skip to content

Instantly share code, notes, and snippets.

@derickr
Created November 21, 2022 10:45
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save derickr/d5fbab31f50e414acedbab99ac0fc596 to your computer and use it in GitHub Desktop.
save-code-coverage.php
<?php
require 'vendor/autoload.php';
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\PHP as PhpReport;
$filter = new Filter;
$filter->includeDirectory( __DIR__ . '/html' );
$filter->includeDirectory( __DIR__ . '/src' );
$filter->includeDirectory( __DIR__ . '/views' );
$coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$filter
);
$coverage->start($_SERVER['REQUEST_URI']);
function save_coverage()
{
global $coverage;
$coverage->stop();
(new PhpReport)->process($coverage, '/tmp/path/crawler/' . bin2hex(random_bytes(16)) . '.cov');
}
register_shutdown_function('save_coverage');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment