-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathphpunit-threshold.php
53 lines (50 loc) · 1.46 KB
/
phpunit-threshold.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
47
48
49
50
51
52
53
<?php
$file = "./.coverage/index.xml";
$coverage = simplexml_load_file($file);
$coverageIsOk = true;
$errorMessage = "";
$totals = [
[
'name' => "Lines",
'threshold' => 51,
'ratio' => (double)$coverage->project->directory->totals->lines["percent"]
],
[
'name' => "Methods",
'threshold' => 47,
'ratio' => (double)$coverage->project->directory->totals->methods["percent"]
],
[
'name' => "Functions",
'threshold' => 0,
'ratio' => (double)$coverage->project->directory->totals->functions["percent"]
],
[
'name' => "Classes",
'threshold' => 22,
'ratio' => (double)$coverage->project->directory->totals->classes["percent"]
],
[
'name' => "Traits",
'threshold' => 0,
'ratio' => (double)$coverage->project->directory->totals->traits["percent"]
]
];
foreach ($totals as $total) {
if ($total['ratio'] < $total['threshold']) {
echo "{$total['name']} coverage failed! \r\n";
echo "{$total['name']} coverage: {$total['ratio']}% \r\n";
echo "Threshold: {$total['threshold']}% \r\n";
$coverageIsOk = false;
$errorMessage .= "{$total['name']} coverage failed! \r\n";
} else {
echo "{$total['name']} coverage success: {$total['ratio']}% \r\n";
}
}
if (!$coverageIsOk) {
echo "Coverage failed! \r\n";
echo $errorMessage;
exit(1);
} else {
echo "Coverage success! \r\n";
}