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
|
|
|
|
23
|
|
|
use function sprintf; |
24
|
|
|
|
25
|
|
|
class ReportService |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $config; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
*/ |
35
|
65 |
|
public function __construct(array $reportConfig) |
36
|
|
|
{ |
37
|
65 |
|
$this->config = $reportConfig; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Generate report. |
42
|
|
|
*/ |
43
|
40 |
|
public function generateReport(CodeCoverage $coverage): void |
44
|
|
|
{ |
45
|
40 |
|
foreach ($this->config as $format => $config) { |
46
|
8 |
|
switch ($format) { |
47
|
40 |
|
case 'clover': |
48
|
10 |
|
$report = new Clover(); |
49
|
10 |
|
$report->process($coverage, $config['target'], $config['name']); |
50
|
10 |
|
break; |
51
|
35 |
|
case 'crap4j': |
52
|
10 |
|
$report = new Crap4j(); |
53
|
10 |
|
$report->process($coverage, $config['target'], $config['name']); |
54
|
10 |
|
break; |
55
|
25 |
|
case 'html': |
56
|
5 |
|
if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) { |
57
|
5 |
|
$report = new HtmlFacade( |
58
|
5 |
|
$config['lowUpperBound'], |
59
|
5 |
|
$config['highLowerBound'], |
60
|
5 |
|
sprintf( |
61
|
3 |
|
' and <a href="https://behat.cc">Behat Code Coverage %s</a>', |
62
|
5 |
|
InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage') |
63
|
3 |
|
) |
64
|
3 |
|
); |
65
|
|
|
} else { |
66
|
|
|
$thresholds = Thresholds::from( |
67
|
|
|
$config['lowUpperBound'], |
68
|
|
|
$config['highLowerBound'], |
69
|
|
|
); |
70
|
|
|
$colors = Colors::from( |
71
|
|
|
$config['colors']['successLow'], |
72
|
|
|
$config['colors']['successMedium'], |
73
|
|
|
$config['colors']['successHigh'], |
74
|
|
|
$config['colors']['warning'], |
75
|
|
|
$config['colors']['danger'], |
76
|
|
|
); |
77
|
|
|
if ($config['customCSSFile']) { |
78
|
|
|
$customCss = CustomCssFile::from($config['customCSSFile']); |
79
|
|
|
} else { |
80
|
|
|
$customCss = CustomCssFile::default(); |
81
|
|
|
} |
82
|
|
|
$report = new HtmlFacade( |
83
|
|
|
sprintf( |
|
|
|
|
84
|
|
|
' and <a href="https://behat.cc">Behat Code Coverage %s</a>', |
85
|
|
|
InstalledVersions::getPrettyVersion('dvdoug/behat-code-coverage') |
86
|
|
|
), |
87
|
|
|
$colors, |
88
|
|
|
$thresholds, |
89
|
|
|
$customCss |
|
|
|
|
90
|
|
|
); |
91
|
|
|
} |
92
|
5 |
|
$report->process($coverage, $config['target']); |
93
|
5 |
|
break; |
94
|
20 |
|
case 'php': |
95
|
5 |
|
$report = new PHP(); |
96
|
5 |
|
$report->process($coverage, $config['target']); |
97
|
5 |
|
break; |
98
|
15 |
|
case 'text': |
99
|
5 |
|
if (InstalledVersions::satisfies(new VersionParser(), 'phpunit/php-code-coverage', '^9.0')) { |
100
|
5 |
|
$report = new Text( |
101
|
5 |
|
$config['lowUpperBound'], |
102
|
5 |
|
$config['highLowerBound'], |
103
|
5 |
|
$config['showUncoveredFiles'], |
104
|
5 |
|
$config['showOnlySummary'] |
105
|
3 |
|
); |
106
|
5 |
|
echo $report->process($coverage, $config['showColors']); |
107
|
|
|
} else { |
108
|
|
|
$thresholds = Thresholds::from( |
109
|
|
|
$config['lowUpperBound'], |
110
|
|
|
$config['highLowerBound'], |
111
|
|
|
); |
112
|
|
|
$report = new Text( |
113
|
|
|
$thresholds, |
114
|
|
|
$config['showUncoveredFiles'], |
115
|
|
|
$config['showOnlySummary'] |
116
|
|
|
); |
117
|
|
|
echo $report->process($coverage, $config['showColors']); |
118
|
|
|
} |
119
|
5 |
|
break; |
120
|
10 |
|
case 'xml': |
121
|
5 |
|
$report = new XmlFacade(''); |
122
|
5 |
|
$report->process($coverage, $config['target']); |
123
|
5 |
|
break; |
124
|
5 |
|
case 'cobertura': |
125
|
5 |
|
$report = new Cobertura(); |
126
|
5 |
|
$report->process($coverage, $config['target']); |
127
|
5 |
|
break; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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