PHPackages                             esi/phpunit-coverage-check - 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. esi/phpunit-coverage-check

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

esi/phpunit-coverage-check
==========================

Check the code coverage using the clover report of PHPUnit.

3.1.0(3mo ago)6142.9k↓17.2%1[2 PRs](https://github.com/ericsizemore/phpunit-coverage-check/pulls)12MITPHPPHP ^8.3CI passing

Since Mar 26Pushed 2mo agoCompare

[ Source](https://github.com/ericsizemore/phpunit-coverage-check)[ Packagist](https://packagist.org/packages/esi/phpunit-coverage-check)[ Docs](https://github.com/ericsizemore/phpunit-coverage-check)[ Fund](https://ko-fi.com/ericsizemore)[ GitHub Sponsors](https://github.com/ericsizemore)[ RSS](/packages/esi-phpunit-coverage-check/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (12)Versions (15)Used By (12)

PHPUnit Coverage Check
======================

[](#phpunit-coverage-check)

[![Build Status](https://camo.githubusercontent.com/c53661e82f7826ea1262c377d9a4bc500e415ef78c788ab31c00e7d40c2b7a3e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f706870756e69742d636f7665726167652d636865636b2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/phpunit-coverage-check/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/303dc42a5ece0f8964503455be6b2983f0300695196d68566c9b556b257b9506/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f706870756e69742d636f7665726167652d636865636b2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/phpunit-coverage-check/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a46b35e07f41cd13116cd983726f06a8aa0999d690eea793779d080f1ff5ac9e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6572696373697a656d6f72652f706870756e69742d636f7665726167652d636865636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ericsizemore/phpunit-coverage-check/?branch=master)[![Continuous Integration](https://github.com/ericsizemore/phpunit-coverage-check/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ericsizemore/phpunit-coverage-check/actions/workflows/continuous-integration.yml)[![SymfonyInsight](https://camo.githubusercontent.com/d92f253f885abef7f809e38c1749077da6ebd2a086cb2739c5ce325adcfb55d8/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f37383432306333662d316634652d346337392d623638342d3033383837373536303833622f6d696e692e737667)](https://insight.symfony.com/projects/78420c3f-1f4e-4c79-b684-03887756083b)[![Type Coverage](https://camo.githubusercontent.com/cbf09828827bf1e09b1a249e2e8ac3969c28ab42b1c06c262413b1d87462d89f/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f706870756e69742d636f7665726167652d636865636b2f636f7665726167652e737667)](https://shepherd.dev/github/ericsizemore/phpunit-coverage-check)[![Psalm Level](https://camo.githubusercontent.com/4c975fa48d3498af41cfb75f5a3fa5e74d3f2661051a2b7b4e70ebe8d4a3d717/68747470733a2f2f73686570686572642e6465762f6769746875622f6572696373697a656d6f72652f706870756e69742d636f7665726167652d636865636b2f6c6576656c2e737667)](https://shepherd.dev/github/ericsizemore/phpunit-coverage-check)[![Quality Gate Status](https://camo.githubusercontent.com/f486fdecc5fbed818cad4796e84f22d03515debcbe61e8dfd0d6ab3ebf5385cc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d6572696373697a656d6f72655f706870756e69742d636f7665726167652d636865636b266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=ericsizemore_phpunit-coverage-check)[![Latest Stable Version](https://camo.githubusercontent.com/316b3e29eb66ac2926c88a05f1c76639c2080483aa8757c23c7fc43f87e81c71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6573692f706870756e69742d636f7665726167652d636865636b2e737667)](https://packagist.org/packages/esi/phpunit-coverage-check)[![Downloads per Month](https://camo.githubusercontent.com/696a72596795df84a043b0dd8fa58f703c807d743391c2f472ff054f446aa4d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6573692f706870756e69742d636f7665726167652d636865636b2e737667)](https://packagist.org/packages/esi/phpunit-coverage-check)[![License](https://camo.githubusercontent.com/b5e4fbd9f6168680e009e6947feb336ae55cee1260968526383d7022eeeadc81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6573692f706870756e69742d636f7665726167652d636865636b2e737667)](https://packagist.org/packages/esi/phpunit-coverage-check)

[PHPUnit Coverage Check](http://github.com/ericsizemore/phpunit-coverage-check/) - Check the code coverage using the clover report of PHPUnit.

This library will read the clover (or openclover in PHPUnit 12.2+) XML report from PHPUnit and calculate the coverage score. Based on the given threshold, the application 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 library can be used in multiple ways:

- In your continuous deployment environment
- By adding it to a pre-commit hook
- Requiring it as a dev dependency in your `composer.json` and running it with a [composer script](https://getcomposer.org/doc/articles/scripts.md).

See [GitHub Action](#github-action), [Installation](#installation) and [Usage](#usage) for more information.

Important

This project is not in any way an official `PHPUnit` project. Meaning it is not associated with, or endorsed by, the `PHPUnit` project or its author `Sebastian Bergmann`.

### GitHub Action

[](#github-action)

A GitHub action is available and can be found in the [PHPUnit Coverage Check Action](https://github.com/ericsizemore/phpunit-coverage-check-action) repository, or on the [GitHub Marketplace](https://github.com/marketplace/actions/phpunit-coverage-check).

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

[](#installation)

### Composer

[](#composer)

`PHPUnit Coverage Check` can be installed using Composer. Add this repository as a dev-dependency to the composer.json file.

```
$ composer require --dev esi/phpunit-coverage-check:^3.1
```

To use PHPUnit Coverage Check on an older version of PHP:

- PHP 8.1, use version 1.0.0 (and check 1.x's [readme](https://github.com/ericsizemore/phpunit-coverage-check/blob/1.x/README.md#usage) as usage is slightly different):

```
$ composer require --dev esi/phpunit-coverage-check:^1.0
```

- PHP 8.2, use version 2.0.0 (and check 2.x's [readme](https://github.com/ericsizemore/phpunit-coverage-check/blob/2.x/README.md#usage))

```
$ composer require --dev esi/phpunit-coverage-check:^2.0
```

### Phar

[](#phar)

Download the `phpunit-coverage-check.phar` from an available release. It is recommended to check the signature when downloading the Phar from a GitHub Release (with `phpunit-coverage-check.phar.asc`).

```
# Adjust the URL based on the latest release
wget -O phpunit-coverage-check.phar "https://github.com/ericsizemore/phpunit-coverage-check/releases/download/3.1.0/phpunit-coverage-check.phar"
wget -O phpunit-coverage-check.phar.asc "https://github.com/ericsizemore/phpunit-coverage-check/releases/download/3.1.0/phpunit-coverage-check.phar.asc"

# Check that the signature matches
gpg --verify phpunit-coverage-check.phar.asc phpunit-coverage-check.phar

# Check the issuer (the ID can also be found from the previous command)
gpg --keyserver hkps://keys.openpgp.org --recv-keys F8367C6E9D7A7028292144AAC9D8B66FF3C06696

rm phpunit-coverage-check.phar.asc
chmod +x phpunit-coverage-check.phar
```

The Phar files of *PHPUnit Coverage Check* are signed with a public key associated to `admin@secondversion.com.`. The [`key(s) associated with this E-Mail address`](https://keys.openpgp.org/search?q=admin%40secondversion.com) can be queried at [`keys.openpgp.org`](https://keys.openpgp.org/).

#### Install with Phive

[](#install-with-phive)

You can also install the *PHPUnit Coverage Check* Phar with `Phive`.

If not already using Phive, you can read more about it [here](https://phar.io/), also Phive [installation](https://phar.io/#Install) and [usage](https://phar.io/#Usage).

Usage
-----

[](#usage)

There are two parameters that must be passed to return the code coverage.

1. The location of the clover XML file that PHPUnit has generated.
2. The coverage threshold that is acceptable or 'passing.' Min = 1, Max = 100.

Generate the `clover.xml` file by using PHPUnit:

#### Prior to PHPUnit 12.2 (or if you prefer the old clover format of PHPUnit)

[](#prior-to-phpunit-122-or-if-you-prefer-the-old-clover-format-of-phpunit)

```
$ php vendor/bin/phpunit --coverage-clover clover.xml
```

You can also add the coverage report generation to your PHPUnit configuration file (`phpunit.xml.dist` for example). You would need to add the following lines inside the `` tag:

```

```

#### PHPUnit 12.2 and later, for OpenClover

[](#phpunit-122-and-later-for-openclover)

For the experimental OpenClover report in PHPUnit 12.2+

```
$ php vendor/bin/phpunit --coverage-openclover clover.xml
```

```

```

- For more information, see the [PHPUnit Documentation](https://docs.phpunit.de/en/12.3/).
- Information about the [configuration file](https://docs.phpunit.de/en/10.5/configuration.html) and [commandline options](https://docs.phpunit.de/en/12.3/textui.html#command-line-options).
- Also see the [release notes](https://github.com/sebastianbergmann/phpunit/releases/tag/12.2.0) for PHPUnit 12.2.0.

### If installed with Composer

[](#if-installed-with-composer)

```
$ php vendor/bin/coverage-check /path/to/clover.xml 100
$ php vendor/bin/coverage-check /path/to/clover.xml 100 --only-percentage

# -O for only-percentage works as well
$ php vendor/bin/coverage-check /path/to/clover.xml 100 -O

# -F or show-files will display coverage per file, formatted in a table
$ php vendor/bin/coverage-check /path/to/clover.xml 100 -F
```

You can use the Api directly if you wish. The `Esi\CoverageCheck\CoverageCheck::nonConsoleCall()` method will process and return the data, like how the console application displays it.

```
    /**
     * Processes the coverage data with the given clover file and threshold, and returns the information
     * like how the Console application will.
     *
     * This is mainly useful for those that may wish to use this library outside the CLI/Console or PHAR.
     */
    public function nonConsoleCall(string $cloverFile, int $threshold = 100, bool $onlyPercentage = false): string
```

An example usage:

```
use Esi\CoverageCheck\CoverageCheck;

$check = new CoverageCheck();
$results = $check->nonConsoleCall(__DIR__ . '/tests/fixtures/clover.xml', 90);

echo $results; // Total code coverage is 90.32%
```

### If using the Phar

[](#if-using-the-phar)

```
$ php phpunit-coverage-check.phar /path/to/clover.xml 100
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 --only-percentage

# -O for only-percentage works as well
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -O

# -F or show-files will display coverage per file, formatted in a table
$ php phpunit-coverage-check.phar /path/to/clover.xml 100 -F
```

With `--only-percentage` (or `-O`) enabled, the CLI command will only return the resulting coverage percentage.

#### --show-files

[](#--show-files)

With `--show-files` (or `-F`), `--only-percentage` will be ignored. This option parses the clover file for coverage information for each file in the project/package, determine coverage, and display the information in a table.

For example:

##### Passing coverage example output

[](#passing-coverage-example-output)

```
$ php coverage-check build/logs/clover.xml 90 -F

 ------------------------------------------------------------------- -------------------------- ----------
  File                                                                Elements (Covered/Total)   Coverage
 ------------------------------------------------------------------- -------------------------- ----------
  [...]\phpunit-coverage-check\src\Application.php                    12/12                      100.00%
  [...]\phpunit-coverage-check\src\Command\CoverageCheckCommand.php   94/94                      100.00%
  [...]\phpunit-coverage-check\src\CoverageCheck.php                  80/80                      100.00%
  [...]\phpunit-coverage-check\src\Style\CoverageCheckStyle.php       12/12                      100.00%
  [...]\phpunit-coverage-check\src\Utils.php                          39/39                      100.00%
 ------------------------------------------------------------------- -------------------------- ----------
  Overall Totals                                                      237/237                    100.00%
 ------------------------------------------------------------------- -------------------------- ----------
```

##### Mixed pass/fail coverage example output

[](#mixed-passfail-coverage-example-output)

```
$ php coverage-check tests/fixtures/clover.xml 90 -F

 ----------------------------- -------------------------- ----------
  File                          Elements (Covered/Total)   Coverage
 ----------------------------- -------------------------- ----------
  /tmp/Example/String.php       36/38                      94.74%
  /tmp/Example/StringList.php   20/24                      83.33%
 ----------------------------- -------------------------- ----------
  Overall Totals                56/62                      89.04%
 ----------------------------- -------------------------- ----------
```

#### --table-width

[](#--table-width)

The `--table-width` (or `-W`) option will only have an affect if used with the `--show-files` option. The only requirement for this particular option is that you must pass an integer value. For example:

```
$ php coverage-check tests/fixtures/clover.xml 90 -F -W 120

# ...or
$ php coverage-check tests/fixtures/clover.xml 90 --show-files --table-width 120
```

About
-----

[](#about)

### Requirements

[](#requirements)

- PHPUnit Coverage Check works with PHP 8.3.0 or above.
- For PHP 8.2 please use [v2.0.x](https://github.com/ericsizemore/phpunit-coverage-check/tree/2.x) of PHPUnit Coverage Check.
- For PHP 8.1 please use [v1.0.x](https://github.com/ericsizemore/phpunit-coverage-check/tree/1.x) of PHPUnit Coverage Check.

### Credits

[](#credits)

This library is a fork of/based upon [rregeer/phpunit-coverage-check](https://github.com/richardregeer/phpunit-coverage-check/) by [Richard Regeer](https://github.com/richardregeer).

Most of this library has been rewritten from the ground up, to replace and improve the majority of the original library. The overall idea, and key pieces of the calculation, are thanks to the original library. Many thanks and much appreciation to Richard Regeer for his wonderful work.

- Author: [Eric Sizemore](https://github.com/ericsizemore)
- Thanks to [Richard Regeer](https://github.com/richardregeer) for the original `phpunit-coverage-check` library this library is forked from.
- Thanks to [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker) for inspiration in creating my implementation of the `coverage:check` command.
- Thanks to [Box](https://github.com/box-project/box) for their wonderful project that makes Phar generation a breeze.
- Thanks to [all Contributors](https://github.com/ericsizemore/phpunit-coverage-check/contributors).

### Contributing

[](#contributing)

See [CONTRIBUTING](./CONTRIBUTING.md).

Bugs and feature requests are tracked on [GitHub](https://github.com/ericsizemore/phpunit-coverage-check/issues).

### Contributor Covenant Code of Conduct

[](#contributor-covenant-code-of-conduct)

See [CODE\_OF\_CONDUCT.md](./CODE_OF_CONDUCT.md)

### Backward Compatibility Promise

[](#backward-compatibility-promise)

See [backward-compatibility.md](./backward-compatibility.md) for more information on Backwards Compatibility.

### Changelog

[](#changelog)

See the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.

### License

[](#license)

See the [LICENSE](./LICENSE) for more information on the license that applies to this project.

### Security

[](#security)

See [SECURITY](./SECURITY.md) for more information on the security disclosure process.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance84

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 74.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~84 days

Recently: every ~105 days

Total

9

Last Release

110d ago

Major Versions

1.x-dev → 2.0.02024-04-21

2.x-dev → 3.0.02024-12-16

PHP version history (3 changes)1.0.0PHP ^8.1 &lt;8.5

2.0.0PHP ^8.2 &lt;8.5

3.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7181952b087db2a847c6b90d5cc5e53948e66229ad16acf92ccca3e8767cb92?d=identicon)[ericsizemore](/maintainers/ericsizemore)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (525 commits)")[![ericsizemore](https://avatars.githubusercontent.com/u/723810?v=4)](https://github.com/ericsizemore "ericsizemore (143 commits)")[![richardregeer](https://avatars.githubusercontent.com/u/16963508?v=4)](https://github.com/richardregeer "richardregeer (15 commits)")[![rregeer](https://avatars.githubusercontent.com/u/4814166?v=4)](https://github.com/rregeer "rregeer (8 commits)")[![ttomdewit](https://avatars.githubusercontent.com/u/2845400?v=4)](https://github.com/ttomdewit "ttomdewit (3 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (3 commits)")[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![n0nag0n](https://avatars.githubusercontent.com/u/2322095?v=4)](https://github.com/n0nag0n "n0nag0n (1 commits)")

---

Tags

code-coveragecode-coverage-checkercoveragecoverage-reporthacktoberfestphpunittesttestingtesting-toolsunit-testingtestingphpunittestunit testingcoveragecode coveragetesting-toolscoverage-reportcode-coverage-checker

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/esi-phpunit-coverage-check/health.svg)

```
[![Health](https://phpackages.com/badges/esi-phpunit-coverage-check/health.svg)](https://phpackages.com/packages/esi-phpunit-coverage-check)
```

###  Alternatives

[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k26.2M1.8k](/packages/infection-infection)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[dvdoug/behat-code-coverage

Generate Code Coverage reports for Behat tests

593.6M37](/packages/dvdoug-behat-code-coverage)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)[ockcyp/covers-validator

Validates @covers tags in PHPUnit tests

21198.0k82](/packages/ockcyp-covers-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
