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

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

orbeji/phpunit-pr-coverage-check
================================

Check the code coverage of a PR using the clover report of phpunit

3.1.0(2mo ago)111.6k↓20%2MITPHPPHP ^8.3CI passing

Since Apr 4Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/orbeji/phpunit-pr-coverage-check)[ Packagist](https://packagist.org/packages/orbeji/phpunit-pr-coverage-check)[ RSS](/packages/orbeji-phpunit-pr-coverage-check/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (15)Versions (10)Used By (0)

Phpunit PR Coverage Check
=========================

[](#phpunit-pr-coverage-check)

 [Report Bug](https://github.com/orbeji/phpunit-pr-coverage-check/issues) · [Request Feature](https://github.com/orbeji/phpunit-pr-coverage-check/issues)

[![Tests](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/tests.yml/badge.svg)](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/tests.yml/badge.svg)[![Static analysis](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/static.yml/badge.svg)](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/static.yml/badge.svg)[![Symfony & php compatibility](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/compatibility.yml/badge.svg)](https://github.com/orbeji/phpunit-pr-coverage-check/actions/workflows/compatibility.yml/badge.svg)

About The Project
-----------------

[](#about-the-project)

Inspired by

This project is a console command that filters the coverage report of your Phpunit tests to only take into account the modifications of a PullRequest, so you can be sure that the PR has enough tests.

([back to top](#readme-top))

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Open a command console, enter your project directory and execute:

```
$ composer require --dev orbeji/phpunit-pr-coverage-check
```

Usage
-----

[](#usage)

There are two ways of using this command:

- Passing a diff file
- Passing git repo information

With the first option you need to generate the appropiate diff file to pass to the command. The diff file must only contain the modified files/lines of the pr. To do that you can call `git diff DESTINATION_BRANCH...PR_BRANCH > diff.txt` with [Bitbucket](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/) and [GitHub](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables)you have environment variables to know the current and destination branches.

Diff file example: Bitbucket

```
vendor/bin/phpunit --configuration phpunit.xml.dist --testsuite pipelines --coverage-clover 'clover.xml'
git diff origin/${BITBUCKET_PR_DESTINATION_BRANCH}...origin/${BITBUCKET_BRANCH} > diff.txt
vendor/bin/pr-coverage-check check clover.xml 100 --diff=diff.txt --report=ansi
```

GitHub

```
vendor/bin/phpunit --coverage-clover clover.xml
git diff ${GITHUB_BASE_REF}...${GITHUB_REF_NAME} > diff.txt
vendor/bin/pr-coverage-check check clover.xml 100 --diff=diff.txt
```

Git repo information

```
vendor/bin/pr-coverage-check check clover.xml 100 --pullrequest-id=1 --provider=Github --workspace=orbeji --repository=test --api_token=API_TOKEN
```

The API token must have permissions to the PullRequest scope.

For GitHub in the workspace option put the owner of the repo.

In any case if the coverage is not met the command will return the covered percentage

```
Coverage 40%
```

### Reports

[](#reports)

When executing the command line you can pass the option `--report` to generate a table with the uncovered lines of the PR

This option accepts 3 values:

- ansi: Coverage table in console output
- comment: Coverage table in PR comment
- report: Bitbucket report

#### Examples:

[](#examples)

ansi:

```
root@bbfb2d246e64:/app# bin/pr-coverage-check check tests/clover.xml 90 --diff=tests/diff.txt --report=ansi
Coverage: 40%
--------------- ------------
File            Uncovered Lines
--------------- ------------
src/Dummy.php   19, 20, 26
--------------- ------------

```

comment: [![](docs/screenshots/github_comment.png)](docs/screenshots/github_comment.png)[![](docs/screenshots/bitbucket_comment.png)](docs/screenshots/bitbucket_comment.png)report:

### CI Integration

[](#ci-integration)

#### Bitbucket Pipelines

[](#bitbucket-pipelines)

```
pipelines:
  pull-requests:
      feature/*:
        - step:
            name: phpunit coverage check
            image:
              name: orbeji/base:7.2-xdebug-cli
            script:
              - composer install
              - vendor/bin/phpunit --configuration phpunit.xml.dist --testsuite pipelines --coverage-clover 'clover.xml'
              - git diff origin/${BITBUCKET_PR_DESTINATION_BRANCH}...origin/${BITBUCKET_BRANCH} > diff.txt
              - vendor/bin/pr-coverage-check check clover.xml 100 --diff=diff.txt --report=ansi
            caches:
              - composer
```

#### GitHub Actions

[](#github-actions)

```
name: PHPUnit and Coverage Check

on: [pull_request]

jobs:
  test:
    runs-on: ubuntu-22.04

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Set up PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '7.2'

    - name: Install dependencies
      run: composer install

    - name: Run PHPUnit with coverage
      run: vendor/bin/phpunit --configuration phpunit.xml.dist --testsuite pipelines --coverage-clover 'clover.xml'

    - name: Git diff
      run: git fetch && git diff origin/${GITHUB_BASE_REF}...origin/${GITHUB_HEAD_REF} > diff.txt

    - name: PR Coverage Check
      run: vendor/bin/pr-coverage-check check clover.xml 100 --diff=diff.txt --report=ansi
```

Roadmap
-------

[](#roadmap)

- Add Bitbucket report example screenshot
- Add examples of CI for Bitbucket and GitHub

See the [open issues](https://github.com/orbeji/phpunit-pr-coverage-check/issues) for a full list of proposed features (and known issues).

([back to top](#readme-top))

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate and that all the GitHub Actions are passing.

([back to top](#readme-top))

License
-------

[](#license)

Distributed under the [MIT](https://choosealicense.com/licenses/mit/) License.

([back to top](#readme-top))

Contact
-------

[](#contact)

Project Link:

([back to top](#readme-top))

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance83

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~137 days

Recently: every ~170 days

Total

6

Last Release

87d ago

Major Versions

1.1.0 → 2.0.02024-11-12

2.0.0 → 3.0.02025-07-01

PHP version history (2 changes)1.0.0PHP ^7.2

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/33424bf57508fd2a971097eae18f07a316f5b4d97e225b7cc31ab74b2353ea04?d=identicon)[orbeji](/maintainers/orbeji)

---

Top Contributors

[![orbeji](https://avatars.githubusercontent.com/u/155294281?v=4)](https://github.com/orbeji "orbeji (14 commits)")

---

Tags

coveragephpprpull-requestphptestingphpunitciunittestpull-requestcode coveragepr

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/orbeji-phpunit-pr-coverage-check/health.svg)](https://phpackages.com/packages/orbeji-phpunit-pr-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)[rregeer/phpunit-coverage-check

Check the code coverage using the clover report of phpunit

606.1M179](/packages/rregeer-phpunit-coverage-check)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)[hot/phpunit-runner

The lib allows to watch phpunit tests

3066.9k4](/packages/hot-phpunit-runner)

PHPackages © 2026

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