php-coverage-ensure
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., (*1)
Requirements
- PHP 7.0+
- php-xdebug extension
- phpunit, for generating code coverage reports
Installation
# In your project:
$ composer require --dev beporter/php-coverage-ensure
Usage
Before calling the script, you must produce a clover coverage report for your project. This can be done with PHPUnit., (*2)
$ 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., (*3)
$ vendor/bin/coverage-ensure tmp/clover.xml 80
Advanced Usage
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:, (*4)
<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:, (*5)
$ vendor/bin/coverage-ensure `vendor/bin/clover-path-from-phpunit` 80
Contributing
Code of Conduct
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., (*6)
Reporting Issues
Please use GitHub Isuses for listing any known defects or issues., (*7)
Development
Please fork this repository, create a new topic branch, and submit a pull request for your work., (*8)
Credits
This work was originally done as a part of loadsys/cakephp-shell-scripts and broken out here for greater portability/reuse., (*9)
License
MIT, (*10)
Copyright
Copyright © 2018 Brian Porter, (*11)