PHPackages                             friends-of-phpspec/phpspec-code-coverage - 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. friends-of-phpspec/phpspec-code-coverage

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

friends-of-phpspec/phpspec-code-coverage
========================================

Generate Code Coverage reports for PhpSpec tests

v7.0.0(7mo ago)202.6M↓30.9%13[4 issues](https://github.com/friends-of-phpspec/phpspec-code-coverage/issues)[1 PRs](https://github.com/friends-of-phpspec/phpspec-code-coverage/pulls)20MITPHPPHP &gt;= 8.1CI passing

Since Feb 11Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/friends-of-phpspec/phpspec-code-coverage)[ Packagist](https://packagist.org/packages/friends-of-phpspec/phpspec-code-coverage)[ Docs](https://github.com/friends-of-phpspec/phpspec-code-coverage)[ RSS](/packages/friends-of-phpspec-phpspec-code-coverage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (34)Used By (20)

[![Latest Stable Version](https://camo.githubusercontent.com/d0ae1c940c7a23703d1ea3d45d3880d5c198cdd81e35362cb2f353d9b70e4a9a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667269656e64732d6f662d706870737065632f706870737065632d636f64652d636f7665726167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friends-of-phpspec/phpspec-code-coverage)[![GitHub stars](https://camo.githubusercontent.com/f0ee92a0dc6a15d866d6ca7f09604f632dc41314d4643cb8e237fe6ca3b74350/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f667269656e64732d6f662d706870737065632f706870737065632d636f64652d636f7665726167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friends-of-phpspec/phpspec-code-coverage)[![Total Downloads](https://camo.githubusercontent.com/51d32d217efa0a142c570ef818b8b6b79d8227ed6d6a39c6872b6c16b3bfd253/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64732d6f662d706870737065632f706870737065632d636f64652d636f7665726167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friends-of-phpspec/phpspec-code-coverage)[![GitHub Workflow Status](https://github.com/friends-of-phpspec/phpspec-code-coverage/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/friends-of-phpspec/phpspec-code-coverage/actions)[![Scrutinizer code quality](https://camo.githubusercontent.com/2abe540b8361e7d2ea12c4674c23d68db46736ff15324953635e5a3e6da3e7ba/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f667269656e64732d6f662d706870737065632f706870737065632d636f64652d636f7665726167652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/friends-of-phpspec/phpspec-code-coverage/?branch=master)[![License](https://camo.githubusercontent.com/eec8f07759b54518c3f206ffa8a9e10505a0334e6d728166f3fcf4838a2c2141/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f667269656e64732d6f662d706870737065632f706870737065632d636f64652d636f7665726167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friends-of-phpspec/phpspec-code-coverage)

phpspec-code-coverage
=====================

[](#phpspec-code-coverage)

[phpspec-code-coverage](https://github.com/friends-of-phpspec/phpspec-code-coverage) is a [PhpSpec](http://www.phpspec.net/en/stable) extension that generates Code Coverage reports for [PhpSpec](http://www.phpspec.net/en/stable) tests.

Generating Code Coverage reports allows you to to analyze which parts of your codebase are tested and how well. However, Code Coverage alone should NOT be used as a single metric defining how good your tests are.

[![phpspec-code-coverage console report](https://camo.githubusercontent.com/22dabff92dd18b7366b737cf95e0189f191804a4fa4099bafb753926bac2228a/68747470733a2f2f692e696d6775722e636f6d2f425531305a41562e706e67)](https://camo.githubusercontent.com/22dabff92dd18b7366b737cf95e0189f191804a4fa4099bafb753926bac2228a/68747470733a2f2f692e696d6775722e636f6d2f425531305a41562e706e67)[![phpspec-code-coverage HTML report](https://camo.githubusercontent.com/442573a9c79d1cbaf0fa7f381cc4fcec7e7ec277af62ee32c99fb8f70e36e7d2/68747470733a2f2f692e696d6775722e636f6d2f367841435231672e706e67)](https://camo.githubusercontent.com/442573a9c79d1cbaf0fa7f381cc4fcec7e7ec277af62ee32c99fb8f70e36e7d2/68747470733a2f2f692e696d6775722e636f6d2f367841435231672e706e67)

Requirements
------------

[](#requirements)

- PHP 7+ (for [PhpSpec](http://www.phpspec.net/en/stable) v4+) or PHP 5.6+ (for [PhpSpec](http://www.phpspec.net/en/stable) v3)
- [Xdebug](https://xdebug.org/), [phpdbg](https://github.com/krakjoe/phpdbg) or [pcov](https://github.com/krakjoe/pcov) extension enabled (PHP 7+ is required for code generation to work with [phpdbg](https://github.com/krakjoe/phpdbg)).

Compatibility
-------------

[](#compatibility)

phpspec-code-coveragePHPphpspecphpunit4.x`^7.1``^4.2 || ^5.0 || ^6.0``^5.0 || ^6.0 || ^7.0`5.x`>= 7.2``^5.0 || ^6.0 || ^7.0``^6.0 || ^7.0 || ^8.0`6.x`>= 7.3``^6.0 || ^7.0``^9.2 || ^10.0 || ^11.0`7.x`>= 8.1``^7.0 || ^8.0``^9.2 || ^10.0 || ^11.0`Change Log
----------

[](#change-log)

Please see [CHANGELOG.md](CHANGELOG.md) for information on recent changes.

Install
-------

[](#install)

Install this package as a development dependency in your project:

```
$ composer require --dev friends-of-phpspec/phpspec-code-coverage

```

Enable extension by editing `phpspec.yml` of your project:

```
extensions:
  FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension: ~
```

This will sufficient to enable Code Coverage generation by using defaults provided by the extension. This extension supports various [configuration options](#Options). For a fully annotated example configuration file check [configuration section](#Configuration).

Usage
-----

[](#usage)

If you execute `phpspec run` command, you will see code coverage generated in `coverage` directory (in `html` format):

```
$ bin/phpspec run

```

**Note!** When generating Code Coverage reports make sure PHP processes run via CLI are not memory limited (i.e. `memory_limit` set to `-1` in `/etc/php/cli/php.ini`).

### Running with phpdbg

[](#running-with-phpdbg)

This extension now supports [phpdbg](https://github.com/krakjoe/phpdbg), which results in faster execution when using more recent versions of PHP. Run `phpspec` via [phpdbg](https://github.com/krakjoe/phpdbg):

```
$ phpdbg -qrr phpspec run

```

**Note!** PHP 7+ is required for code generation to work with [phpdbg](https://github.com/krakjoe/phpdbg).

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

[](#configuration)

You can see fully annotated `phpspec.yml` example file below, which can be used as a starting point to further customize the defaults of the extension. The configuration file below has all of the [Configuration Options](#Options).

```
# phpspec.yml
# ...
extensions:
  # ... other extensions ...
  # friends-of-phpspec/phpspec-code-coverage
  FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension:
    # Specify a list of formats in which code coverage report should be
    # generated.
    # Default: [html]
    format:
      - text
      - html
      #- clover
      #- php
      #- xml
      #- cobertura
    #
    # Specify output file/directory where code coverage report will be
    # generated. You can configure different output file/directory per
    # enabled format.
    # Default: coverage
    output:
      html: coverage
      #clover: coverage.xml
      #php: coverage.php
      #xml: coverage
      #cobertura: cobertura.xml
    #
    # Should uncovered files be included in the reports?
    # Default: true
    #show_uncovered_files: true
    #
    # Set lower upper bound for code coverage
    # Default: 35
    #lower_upper_bound: 35
    #
    # Set high lower bound for code coverage
    # Default: 70
    #high_lower_bound: 70
    #
    # Whilelist directories for which code generation should be done
    # Default: [src, lib]
    #
    # Should text output show only summary?
    # Default: false
    #show_only_summary: true
    #
    whitelist:
      - src
      - lib
      # or to apply filtering on files names
      #- directory: src
      #  suffix: "Controller.php"
      #  prefix: "Get"
    #
    # Whiltelist files for which code generation should be done
    # Default: empty
    #whilelist_files:
      #- app/bootstrap.php
      #- web/index.php
    #
    # Blacklist directories for which code generation should NOT be done
    #blacklist:
      #- src/legacy
      # or to apply filtering on files names
      #- directory: src/legacy
      #  suffix: "Spec.php"
      #  prefix: "Test"
    #
    # Blacklist files for which code generation should NOT be done
    #blacklist_files:
      #- lib/bootstrap.php
```

### Options

[](#options)

- `format` (optional) a list of formats in which code coverage should be generated. Can be one or many of: `clover`, `cobertura`, `crap4j`, `php`, `text`, `html`, `xml` (default `html`) **Note**: When using `clover` format option, you have to configure specific `output` file for the `clover` format (see below).
- `output` (optional) sets an output file/directory where specific code coverage format will be generated. If you configure multiple formats, takes a hash of `format:output` (e.g. `clover:coverage.xml`) (default `coverage`)
- `show_only_summary` (optional) for showing only summary in text report (default `false`)
- `show_uncovered_files` (optional) for including uncovered files in coverage reports (default `true`)
- `lower_upper_bound` (optional) sets lower upper bound for code coverage (default `35`).
- `high_lower_bound` (optional) sets high lower bound for code coverage (default `70`)
- `whitelist` takes an array of directories to whitelist (default: `lib`, `src`). The array can be made more specific if an associative array is given with the following keys (`directory`, `prefix`, `suffix`)
- `whitelist_files` takes an array of files to whitelist (default: none).
- `blacklist` takes an array of directories to blacklist (default: `test, vendor, spec`). The array can be made more specific if an associative array is given with the following keys (`directory`, `prefix`, `suffix`)
- `blacklist_files` takes an array of files to blacklist

Authors
-------

[](#authors)

Copyright (c) 2017-2018 ek9  ().

Copyright (c) 2013-2016 Henrik Bjornskov, for portions of code from [henrikbjorn/phpspec-code-coverage](https://github.com/henrikbjorn/PhpSpecCodeCoverageExtension) project.

License
-------

[](#license)

Licensed under [MIT License](LICENSE).

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance58

Moderate activity, may be stable

Popularity52

Moderate usage in the ecosystem

Community44

Growing community involvement

Maturity83

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~131 days

Recently: every ~236 days

Total

25

Last Release

234d ago

Major Versions

v3.1.1 → v4.0.02017-10-17

v4.3.2 → v5.0.02020-11-16

v5.0.0 → v6.0.02020-11-30

v4.3.3 → v6.1.02021-03-30

v6.5.0 → v7.0.02025-09-26

PHP version history (9 changes)v1.0.1PHP &gt;=5.3.3

v2.1.0PHP ~5.3,^5.3.3||~7.0

v3.0.1PHP ~5.6||~7.0

v4.0.0PHP ^7.0

v4.2.0PHP ^7.1

v5.0.0PHP &gt;= 7.2

v6.0.0PHP &gt;= 7.3

v4.3.3PHP &gt;= 7.1.3

v7.0.0PHP &gt;= 8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ab317af777924eeefe097aa3e0a423f069eaac20280e3241631e1a950e17f47?d=identicon)[shulard](/maintainers/shulard)

![](https://www.gravatar.com/avatar/5d7eebb96db1721780c3e38450c4408c15b3fde74daaefdd1412508224d4b7b5?d=identicon)[jaylinski](/maintainers/jaylinski)

---

Top Contributors

[![ek9](https://avatars.githubusercontent.com/u/17393048?v=4)](https://github.com/ek9 "ek9 (98 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (73 commits)")[![henrikbjorn](https://avatars.githubusercontent.com/u/19725?v=4)](https://github.com/henrikbjorn "henrikbjorn (45 commits)")[![drupol](https://avatars.githubusercontent.com/u/252042?v=4)](https://github.com/drupol "drupol (18 commits)")[![jaylinski](https://avatars.githubusercontent.com/u/1668766?v=4)](https://github.com/jaylinski "jaylinski (12 commits)")[![kwisatz](https://avatars.githubusercontent.com/u/237949?v=4)](https://github.com/kwisatz "kwisatz (7 commits)")[![svemir](https://avatars.githubusercontent.com/u/154453?v=4)](https://github.com/svemir "svemir (4 commits)")[![Sam-Burns](https://avatars.githubusercontent.com/u/6594039?v=4)](https://github.com/Sam-Burns "Sam-Burns (4 commits)")[![lookitsatravis](https://avatars.githubusercontent.com/u/606978?v=4)](https://github.com/lookitsatravis "lookitsatravis (3 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (3 commits)")[![balazscsaba2006](https://avatars.githubusercontent.com/u/1202594?v=4)](https://github.com/balazscsaba2006 "balazscsaba2006 (3 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![exu](https://avatars.githubusercontent.com/u/30776?v=4)](https://github.com/exu "exu (2 commits)")[![fesor](https://avatars.githubusercontent.com/u/172247?v=4)](https://github.com/fesor "fesor (2 commits)")[![unixslayer](https://avatars.githubusercontent.com/u/1131246?v=4)](https://github.com/unixslayer "unixslayer (2 commits)")[![michaldudek](https://avatars.githubusercontent.com/u/802141?v=4)](https://github.com/michaldudek "michaldudek (2 commits)")[![milan](https://avatars.githubusercontent.com/u/3963?v=4)](https://github.com/milan "milan (2 commits)")[![DavidGarciaCat](https://avatars.githubusercontent.com/u/7809429?v=4)](https://github.com/DavidGarciaCat "DavidGarciaCat (2 commits)")[![pamil](https://avatars.githubusercontent.com/u/1897953?v=4)](https://github.com/pamil "pamil (2 commits)")[![ptondereau](https://avatars.githubusercontent.com/u/4287777?v=4)](https://github.com/ptondereau "ptondereau (2 commits)")

---

Tags

code-coveragephpspecphpspec-extensiontestcoveragetestsreportspecphpspeccode coverage

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/friends-of-phpspec-phpspec-code-coverage/health.svg)

```
[![Health](https://phpackages.com/badges/friends-of-phpspec-phpspec-code-coverage/health.svg)](https://phpackages.com/packages/friends-of-phpspec-phpspec-code-coverage)
```

###  Alternatives

[dvdoug/behat-code-coverage

Generate Code Coverage reports for Behat tests

593.6M37](/packages/dvdoug-behat-code-coverage)[leanphp/behat-code-coverage

Generate Code Coverage reports for Behat tests

50359.8k2](/packages/leanphp-behat-code-coverage)[benconstable/phpspec-laravel

Test your Laravel applications with PhpSpec

144347.1k15](/packages/benconstable-phpspec-laravel)

PHPackages © 2026

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