Skip to content
Generate Code Coverage reports for PhpSpec tests
Branch: master
Clone or download
Pull request Compare This branch is 27 commits ahead of leanphp:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Latest Stable Version Total Downloads Scrutinizer Code Quality Travis

phpspec-code-coverage is a PhpSpec extension that generates Code Coverage reports for PhpSpec 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 phpspec-code-coverage HTML report


Change Log

Please see for information on recent changes.


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:

  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. For a fully annotated example configuration file check Configuration section.


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

This extension now supports phpdbg, which results in faster execution when using more recent versions of PHP. Run phpspec via phpdbg:

$ phpdbg -qrr phpspec run

Note! PHP 7+ is required for code generation to work with phpdbg.


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.

# phpspec.yml
# ...
  # ... other extensions ...
  # friends-of-phpspec/phpspec-code-coverage
    # Specify a list of formats in which code coverage report should be
    # generated.
    # Default: [html]
      - text
      - html
      #- clover
      #- php
      #- xml
    # Specify output file/directory where code coverage report will be
    # generated. You can configure different output file/directory per
    # enabled format.
    # Default: coverage
      html: coverage
      #clover: coverage.xml
      #php: coverage.php
      #xml: coverage
    # 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]
      - src
      - lib
    # Whiltelist files for which code generation should be done
    # Default: empty
      #- app/bootstrap.php
      #- web/index.php
    # Blacklist directories for which code generation should NOT be done
      #- src/legacy
    # Blacklist files for which code generation should NOT be done
      #- lib/bootstrap.php


  • format (optional) a list of formats in which code coverage should be generated. Can be one or many of: clover, 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_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).
  • whitelist_files takes an array of files to whitelist (default: none).
  • blacklist takes an array of directories to blacklist (default: test, vendor, spec)
  • blacklist_files takes an array of files to blacklist


Copyright (c) 2017-2018 ek9 (

Copyright (c) 2013-2016 Henrik Bjornskov, for portions of code from henrikbjorn/phpspec-code-coverage project.


Licensed under MIT License.

You can’t perform that action at this time.