forked from nanoninja/docker-nginx-php-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-coverage.php
32 lines (26 loc) · 953 Bytes
/
check-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
<?php
$inputFile = $argv[1];
$percentage = min(100, max(0, (int) $argv[2]));
if (empty($inputFile)) {
$inputFile = './coverage/coverage.xml';
}
if (!file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}
if (!$percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
}
$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//file/metrics');
$totalElements = 0;
$checkedElements = 0;
foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}
$coverage = (($checkedElements / $totalElements) * 100);
if ($coverage < $percentage) {
echo 'Code coverage is '.$coverage.'%, which is below the accepted '.$percentage.'%'.PHP_EOL;
exit(1);
}
echo 'Code coverage is '.$coverage.'% - OK!'.PHP_EOL;