├── LICENSE ├── README.md ├── bin └── php-coverage-checker ├── composer.json └── coverage-checker.php /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Marco Pivetta 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-coverage-checker 2 | 3 | php-coverage-checker is a library for automated code coverage percentage checking. 4 | 5 | Initial commit is 100% the work of [Ocramius](https://github.com/ocramius): https://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/ 6 | 7 | ## Installation 8 | 9 | Composer! 10 | 11 | `composer require --dev michaelmoussa/php-coverage-checker` 12 | 13 | ## Usage 14 | 15 | 1. Generate [XML Code Coverage](https://phpunit.de/manual/current/en/logging.html#logging.codecoverage.xml) using [PHPUnit](https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.logging) 16 | 1. Run `vendor/bin/php-coverage-checker /path/to/clover.xml ` 17 | * e.g. `vendor/bin/php-coverage-checker build/clover.xml 100` 18 | -------------------------------------------------------------------------------- /bin/php-coverage-checker: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | xpath('//metrics'); 16 | $totalElements = 0; 17 | $checkedElements = 0; 18 | 19 | foreach ($metrics as $metric) { 20 | $totalElements += (int) $metric['elements']; 21 | $checkedElements += (int) $metric['coveredelements']; 22 | } 23 | 24 | $coverage = ($totalElements === 0) ? 0 : ($checkedElements / $totalElements) * 100; 25 | 26 | if ($coverage < $percentage) { 27 | echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; 28 | exit(1); 29 | } 30 | 31 | echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL; 32 | --------------------------------------------------------------------------------