|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Behat Code Coverage |
|
4
|
|
|
*/ |
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace DVDoug\Behat\CodeCoverage\Service; |
|
8
|
|
|
|
|
9
|
|
|
use Composer\InstalledVersions; |
|
10
|
|
|
use Composer\Semver\VersionParser; |
|
11
|
|
|
use SebastianBergmann\CodeCoverage\CodeCoverage; |
|
12
|
|
|
use SebastianBergmann\CodeCoverage\Report\Clover; |
|
13
|
|
|
use SebastianBergmann\CodeCoverage\Report\Cobertura; |
|
14
|
|
|
use SebastianBergmann\CodeCoverage\Report\Crap4j; |
|
15
|
|
|
use SebastianBergmann\CodeCoverage\Report\Html\Colors; |
|
|
|
|
|
|
16
|
|
|
use SebastianBergmann\CodeCoverage\Report\Html\CustomCssFile; |
|
|
|
|
|
|
17
|
|
|
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade; |
|
18
|
|
|
use SebastianBergmann\CodeCoverage\Report\PHP; |
|
19
|
|
|
use SebastianBergmann\CodeCoverage\Report\Text; |
|
20
|
|
|
use SebastianBergmann\CodeCoverage\Report\Thresholds; |
|
|
|
|
|
|
21
|
|
|
use SebastianBergmann\CodeCoverage\Report\Xml\Facade as XmlFacade; |
|
22
|
|
|
use function sprintf; |
|
23
|
|
|
|
|
24
|
|
|
class ReportService |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private $config; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor. |
|
33
|
|
|
*/ |
|
34
|
39 |
|
public function __construct(array $reportConfig) |
|
35
|
|
|
{ |
|
36
|
39 |
|
$this->config = $reportConfig; |
|
37
|
26 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Generate report. |
|
41
|
|
|
*/ |
|
42
|
24 |
|
public function generateReport(CodeCoverage $coverage): void |
|
43
|
|
|
{ |
|
44
|
24 |
|
foreach ($this->config as $format => $config) { |
|
45
|
16 |
|
switch ($format) { |
|
46
|
24 |
|
case 'clover': |
|
47
|
6 |
|
$report = new Clover(); |
|
48
|
6 |
|
$report->process($coverage, $config['target'], $config['name']); |
|
49
|
6 |
|
break; |
|
50
|
21 |
|
case 'crap4j': |
|
51
|
6 |
|
$report = new Crap4j(); |
|
52
|
6 |
|
$report->process($coverage, $config['target'], $config['name']); |
|
53
|
6 |
|
break; |
|
54
|
15 |
|
case 'html': |
|
55
|
3 |
|
if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) { |
|
56
|
3 |
|
$report = new HtmlFacade( |
|
57
|
3 |
|
$config['lowUpperBound'], |
|
58
|
3 |
|
$config['highLowerBound'], |
|
59
|
3 |
|
sprintf( |
|
60
|
1 |
|
' and <a href="https://behat.cc">Behat Code Coverage %s</a>', |
|
61
|
3 |
|
InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage') |
|
62
|
|
|
) |
|
63
|
|
|
); |
|
64
|
|
|
} else { |
|
65
|
|
|
$thresholds = Thresholds::from( |
|
66
|
|
|
$config['lowUpperBound'], |
|
67
|
|
|
$config['highLowerBound'], |
|
68
|
|
|
); |
|
69
|
|
|
$colors = Colors::from( |
|
70
|
|
|
$config['colors']['successLow'], |
|
71
|
|
|
$config['colors']['successMedium'], |
|
72
|
|
|
$config['colors']['successHigh'], |
|
73
|
|
|
$config['colors']['warning'], |
|
74
|
|
|
$config['colors']['danger'], |
|
75
|
|
|
); |
|
76
|
|
|
if ($config['customCSSFile']) { |
|
77
|
|
|
$customCss = CustomCssFile::from($config['customCSSFile']); |
|
78
|
|
|
} else { |
|
79
|
|
|
$customCss = CustomCssFile::default(); |
|
80
|
|
|
} |
|
81
|
|
|
$report = new HtmlFacade( |
|
82
|
|
|
sprintf( |
|
|
|
|
|
|
83
|
|
|
' and <a href="https://behat.cc">Behat Code Coverage %s</a>', |
|
84
|
|
|
InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage') |
|
85
|
|
|
), |
|
86
|
|
|
$colors, |
|
87
|
|
|
$thresholds, |
|
88
|
|
|
$customCss |
|
|
|
|
|
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
3 |
|
$report->process($coverage, $config['target']); |
|
92
|
3 |
|
break; |
|
93
|
12 |
|
case 'php': |
|
94
|
3 |
|
$report = new PHP(); |
|
95
|
3 |
|
$report->process($coverage, $config['target']); |
|
96
|
3 |
|
break; |
|
97
|
9 |
|
case 'text': |
|
98
|
3 |
|
if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) { |
|
99
|
3 |
|
$report = new Text( |
|
100
|
3 |
|
$config['lowUpperBound'], |
|
101
|
3 |
|
$config['highLowerBound'], |
|
102
|
3 |
|
$config['showUncoveredFiles'], |
|
103
|
3 |
|
$config['showOnlySummary'] |
|
104
|
|
|
); |
|
105
|
3 |
|
echo $report->process($coverage, $config['showColors']); |
|
106
|
|
|
} else { |
|
107
|
|
|
$thresholds = Thresholds::from( |
|
108
|
|
|
$config['lowUpperBound'], |
|
109
|
|
|
$config['highLowerBound'], |
|
110
|
|
|
); |
|
111
|
|
|
$report = new Text( |
|
112
|
|
|
$thresholds, |
|
113
|
|
|
$config['showUncoveredFiles'], |
|
114
|
|
|
$config['showOnlySummary'] |
|
115
|
|
|
); |
|
116
|
|
|
echo $report->process($coverage, $config['showColors']); |
|
117
|
|
|
} |
|
118
|
3 |
|
break; |
|
119
|
6 |
|
case 'xml': |
|
120
|
3 |
|
$report = new XmlFacade(''); |
|
121
|
3 |
|
$report->process($coverage, $config['target']); |
|
122
|
3 |
|
break; |
|
123
|
3 |
|
case 'cobertura': |
|
124
|
3 |
|
$report = new Cobertura(); |
|
125
|
3 |
|
$report->process($coverage, $config['target']); |
|
126
|
3 |
|
break; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
16 |
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths