Skip to content

Instantly share code, notes, and snippets.

@derickr
Last active September 16, 2024 16:46
Show Gist options
  • Save derickr/d5fbab31f50e414acedbab99ac0fc596 to your computer and use it in GitHub Desktop.
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;
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
$filter = new Filter;
$filter->includeFiles((new FileIteratorFacade)->getFilesAsArray( __DIR__ . '/html'));
$filter->includeFiles((new FileIteratorFacade)->getFilesAsArray( __DIR__ . '/src'));
$filter->includeFiles((new FileIteratorFacade)->getFilesAsArray( __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');
?>
@derickr
Copy link
Author

derickr commented Sep 16, 2024

I've updated the GIST to use the FileIterator manually now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment