forked from OPSnet/Gazelle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-coverage.php
46 lines (39 loc) · 1.48 KB
/
ci-coverage.php
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
37
38
39
40
41
42
43
44
45
46
<?php
require_once(__DIR__ . '/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\CodeCoverage\Util\Filesystem;
class CoverageHelper {
/*
* ensure coverage is saved if die() is called somewhere
*/
const TARGET_DIR = '/tmp/coverage';
private CodeCoverage $coverage;
public function __construct() {
$filter = new Filter;
$filter->includeDirectory(__DIR__ . '/app');
$filter->includeDirectory(__DIR__ . '/classes');
$filter->includeDirectory(__DIR__ . '/lib');
$filter->includeDirectory(__DIR__ . '/public');
$filter->includeDirectory(__DIR__ . '/sections');
$this->coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$filter
);
$this->coverage->cacheStaticAnalysis('/tmp/coverage-cache');
$this->coverage->start('fpm-coverage');
}
public function __destruct() {
$this->coverage->stop();
Filesystem::createDirectory($this::TARGET_DIR);
$outfile = tempnam($this::TARGET_DIR, 'phpcov');
if ($outfile !== false) {
(new PhpReport)->process($this->coverage, $outfile);
rename($outfile, $outfile . ".cov");
}
}
}
$coverage_helper = new CoverageHelper();
require_once(__DIR__ . '/gazelle.php');