-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathcheck-coverage.php
More file actions
46 lines (34 loc) · 1.31 KB
/
Copy pathcheck-coverage.php
File metadata and controls
46 lines (34 loc) · 1.31 KB
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
declare(strict_types=1);
/*
* This file is part of php-cache organization.
*
* (c) 2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
$arguments = $_SERVER['argv'] ?? null;
if (!is_array($arguments) || 3 !== count($arguments) || !is_string($arguments[1]) || !is_string($arguments[2])) {
fwrite(\STDERR, "Usage: check-coverage.php <clover.xml> <minimum-percent>\n");
exit(2);
}
$coverage = simplexml_load_file($arguments[1]);
if (false === $coverage || !isset($coverage->project->metrics)) {
fwrite(\STDERR, sprintf("Could not read Clover metrics from %s.\n", $arguments[1]));
exit(2);
}
$metrics = $coverage->project->metrics;
$statements = (int) $metrics['statements'];
$coveredStatements = (int) $metrics['coveredstatements'];
$minimum = (float) $arguments[2];
if (0 === $statements) {
fwrite(\STDERR, "The coverage report does not contain executable statements.\n");
exit(2);
}
$percentage = 100 * $coveredStatements / $statements;
printf("Line coverage: %.2f%% (%d/%d)\n", $percentage, $coveredStatements, $statements);
if ($percentage < $minimum) {
fwrite(\STDERR, sprintf("Coverage must be at least %.2f%%.\n", $minimum));
exit(1);
}