Last active
September 16, 2024 16:46
-
-
Save derickr/d5fbab31f50e414acedbab99ac0fc596 to your computer and use it in GitHub Desktop.
save-code-coverage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the GIST to use the FileIterator manually now.