A composer package that provides a PHP CLI script able to clover.xml coverage reports and return non-zero when percent coverage is below specified threshold. Intended for use with automated test/build tools like Travis CI, Circle CI and Jenkins.
- PHP 7.0+
- php-xdebug extension
- phpunit, for generating code coverage reports
# In your project:
$ composer require --dev beporter/php-coverage-ensure
Before calling the script, you must produce a clover coverage report for your project. This can be done with PHPUnit.
$ vendor/bin/phpunit --coverage-clover tmp/clover.xml
Then call the script providing the path to a clover XML coverage report file and an optional minimum acceptable percentage.
$ vendor/bin/coverage-ensure tmp/clover.xml 80
If you want PHPUnit to always generate a clover report, you can also add the following block to your phpunit.xml
or phpunit.xml.dist
file:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
>
<!-- ... -->
<!-- Always generate a clover coverage report. -->
<logging>
<log type="coverage-clover" target="tmp/clover.xml"/>
</logging>
</phpunit>
This package also includes a helper script that can determine the location of your clover report file by reading your phpunit config file:
$ vendor/bin/coverage-ensure `vendor/bin/clover-path-from-phpunit` 80
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. Translations are available.
Please use GitHub Isuses for listing any known defects or issues.
Please fork this repository, create a new topic branch, and submit a pull request for your work.
This work was originally done as a part of loadsys/cakephp-shell-scripts and broken out here for greater portability/reuse.
Copyright © 2018 Brian Porter