PHPackages                             robiningelbrecht/phpunit-coverage-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. robiningelbrecht/phpunit-coverage-tools

ActiveLibrary[Testing &amp; Quality](/categories/testing)

robiningelbrecht/phpunit-coverage-tools
=======================================

PHPUnit coverage tools

v1.10.0(2mo ago)1783.0k↑11.8%4[1 issues](https://github.com/robiningelbrecht/phpunit-coverage-tools/issues)20MITPHPPHP ^8.1CI passing

Since Apr 24Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/robiningelbrecht/phpunit-coverage-tools)[ Packagist](https://packagist.org/packages/robiningelbrecht/phpunit-coverage-tools)[ RSS](/packages/robiningelbrecht-phpunit-coverage-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (19)Used By (20)

PHPUnit Coverage tools
======================

[](#phpunit-coverage-tools)

[![CI](https://github.com/robiningelbrecht/phpunit-coverage-tools/actions/workflows/ci.yml/badge.svg)](https://github.com/robiningelbrecht/phpunit-coverage-tools/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/b3b058a5c7b032e37e15d04f63755527f49f493bca83a28a3aa915897ed25e31/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f62696e696e67656c6272656368742f706870756e69742d636f7665726167652d746f6f6c733f636f6c6f723d343238663765266c6f676f3d6f70656e253230736f75726365253230696e6974696174697665266c6f676f436f6c6f723d7768697465)](https://github.com/robiningelbrecht/phpunit-coverage-tools/blob/master/LICENSE)[![](https://camo.githubusercontent.com/57bfeca860f545480f5f7371555ad0383b7a6228951b054319b726529fea2132/68747470733a2f2f636f6465636f762e696f2f67682f726f62696e696e67656c6272656368742f706870756e69742d636f7665726167652d746f6f6c732f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4f3071656b4b52797563)](https://codecov.io/gh/robiningelbrecht/phpunit-coverage-tools)[![PHPStan Enabled](https://camo.githubusercontent.com/cb01a196883cd3d15842161f335945a81aff81c4c55d44b9f3b9a648ebf0f774/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d7375636365732e7376673f6c6f676f3d706870266c6f676f436f6c6f723d776869746526636f6c6f723d333143363532)](https://phpstan.org/)[![PHP](https://camo.githubusercontent.com/4b408b5cbb8bfb5bc889d5807ac43534909f4f00150dfc28a28778811fa3da7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f62696e696e67656c6272656368742f706870756e69742d636f7665726167652d746f6f6c733f636f6c6f723d253233373737626233266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://php.net/)[![PHPUnit](https://camo.githubusercontent.com/3e7695bc6df8b78e7b5c675f6b31a5e5d997c7a608edd6d255f18d0ffa1ad9dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f726f62696e696e67656c6272656368742f706870756e69742d636f7665726167652d746f6f6c732f706870756e69742f706870756e69742e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://phpunit.de/)[![PHPUnit](https://camo.githubusercontent.com/79afd59bbba69f533da64619acbd321c7fdd45e4fe9501dd9509931b055682cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f62696e696e67656c6272656368742f706870756e69742d636f7665726167652d746f6f6c733f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://github.com/robiningelbrecht/phpunit-coverage-tools)

---

This extension allows you to enforce minimum code coverage by using the clover xml report from PHPUnit. Based on the given threshold the testsuite will exit ok if the coverage is higher than the threshold or exit with code 1 if the coverage is lower than the threshold. This can be used in your continuous deployment environment or can be added to a pre-commit hook.

Installation
------------

[](#installation)

```
> composer require robiningelbrecht/phpunit-coverage-tools --dev
```

Configuration
-------------

[](#configuration)

Navigate to your `phpunit.xml.dist` file and add following config to set default options:

```

```

Usage
-----

[](#usage)

Just run your testsuite like you normally would, but add following arguments:

### --min-coverage=`[INTEGER]`

[](#--min-coverageinteger)

```
> vendor/bin/phpunit --coverage-clover=path/to/clover.xml -d --min-coverage=100
```

When assigning an integer between 0 - 100, you enforce a minimum code coverage for all your classes. In other words, the total coverage of your project has to be higher than this threshold.

### --min-coverage=`[path/to/min-coverage-rules.php]`

[](#--min-coveragepathtomin-coverage-rulesphp)

```
 > vendor/bin/phpunit --coverage-clover=path/to/clover.xml -d --min-coverage="path/to/min-coverage-rules.php"
```

When referencing a PHP config file, you can configure more complex rules. This allows you to be stricter for critical parts of your application and less strict for parts of your app that are not that critical.

For example:

```
