-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.php-code-coverage.php
More file actions
36 lines (28 loc) · 1011 Bytes
/
.php-code-coverage.php
File metadata and controls
36 lines (28 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\Driver\Selector;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\PHP as PhpReport;
if ((getenv('XDEBUG_MODE') !== 'coverage') && (ini_get('xdebug.mode') !== 'coverage')) {
return;
}
$dir = __DIR__ . '/.coverage/files/';
$files = [];
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src', RecursiveDirectoryIterator::SKIP_DOTS)) as $file ) {
if ($file->getExtension() !== 'php') {
continue;
}
$files[] = $file->getPathname();
}
$filter = new Filter();
$filter->includeFiles($files);
$coverage = new CodeCoverage(
(new Selector())->forLineCoverage($filter),
$filter
);
$coverage->start($_SERVER['REQUEST_URI']);
register_shutdown_function(function () use ($coverage, $dir) {
$coverage->stop();
$basename = $dir . bin2hex(random_bytes(16));
(new PhpReport)->process($coverage, $basename . '.cov');
});