whatisgithub

What is php-code-coverage?

sebastianbergmann/php-code-coverage — explained in plain English

Analysis updated 2026-06-24

8,927PHPAudience · developerComplexity · 2/5Setup · easy

In one sentence

A PHP library that tracks which lines of your code are executed during tests, helping you find untested parts of your codebase. Most developers use it through PHPUnit, but it can also run standalone.

Mindmap

mindmap
  root((php-code-coverage))
    What it does
      Tracks tested lines
      Finds untested code
      Generates reports
    Report formats
      OpenClover XML
      HTML output
    Usage
      Via PHPUnit
      Standalone library
    Setup
      Composer install
      Dev dependency only
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add code coverage reporting to your PHPUnit test suite to see which functions are never tested.

USE CASE 2

Integrate coverage data into a CI pipeline via OpenClover XML output for quality dashboards.

USE CASE 3

Build a custom test runner that collects and processes PHP code coverage without using PHPUnit.

USE CASE 4

Generate coverage reports from previously saved data to track coverage trends over time.

What is it built with?

PHPComposerPHPUnit

How does it compare?

sebastianbergmann/php-code-coveragerss-bridge/rss-bridgefuzzdb-project/fuzzdb
Stars8,9278,9338,902
LanguagePHPPHPPHP
Setup difficultyeasyeasyeasy
Complexity2/52/52/5
Audiencedevelopergeneralops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

So what is it?

php-code-coverage is a PHP library that measures which lines of your code actually run when your tests execute. This is called code coverage: the idea is to see which parts of your codebase are being tested and which parts are being missed. Once you know that, you can decide where to add more tests. The library handles three steps: collecting the raw data as tests run, processing it, and then producing reports. The reports can be generated in several formats. The README shows an example producing an OpenClover XML file, which is a format that many continuous integration tools and code quality dashboards can read. In practice, most PHP developers encounter this library indirectly through PHPUnit, which is the standard testing framework for PHP. PHPUnit uses php-code-coverage under the hood when you run tests with coverage reporting turned on. The library is also available as a standalone dependency for developers who want to integrate coverage tracking into their own tools or custom test setups. Installing it requires Composer, the standard PHP package manager, and it is typically added as a development-only dependency since coverage reporting is not needed in production. The README is brief and focused, covering installation and two code examples: one for collecting coverage during a live test run, and one for loading previously saved coverage data and generating a report from it. The repository is maintained by Sebastian Bergmann, who also created PHPUnit, and it lives under the phpunit namespace on Packagist.

Copy-paste prompts

Prompt 1
I'm using php-code-coverage standalone (not through PHPUnit). Show me how to collect coverage for a single PHP file and generate an OpenClover XML report.
Prompt 2
My PHPUnit coverage report shows low coverage on a specific class. Give me a step-by-step guide to write tests that cover the missing lines.
Prompt 3
Show me the minimal PHP code to start collecting coverage, stop collecting, and export a report using the php-code-coverage library directly.
Prompt 4
How do I load a previously saved php-code-coverage data file and generate an HTML report from it?

Frequently asked questions

What is php-code-coverage?

A PHP library that tracks which lines of your code are executed during tests, helping you find untested parts of your codebase. Most developers use it through PHPUnit, but it can also run standalone.

What language is php-code-coverage written in?

Mainly PHP. The stack also includes PHP, Composer, PHPUnit.

How hard is php-code-coverage to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is php-code-coverage for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.