PHP Classes

File: contrib/coverage-checker.php

Recommend this page to a friend!
  Packages of Leonardo Di Sarli   PHP HTTP Request Library for Services   contrib/coverage-checker.php   Download  
File: contrib/coverage-checker.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP HTTP Request Library for Services
Send HTTP requests to Web services
Author: By
Last change:
Date: 3 years ago
Size: 940 bytes
 

 

Contents

Class file image Download
<?php
$inputFile  = $argv[1];
$percentage = min(
    100,
    max(
        0,
        (int) $argv[2]
    )
);

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(
    '//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;