Freedom251 › Test Coverage Tools
PHP_CodeCoverage

What PHP_CodeCoverage is
PHP_CodeCoverage is an open-source PHP library for collecting, processing, and rendering code coverage information. Add it to a project with Composer, either as a local dependency or as a development dependency when it is only needed during development. Its coverage measures include lines, branches, paths, functions and methods, classes and traits, and the CRAP index. PCOV supports line coverage; branch and path coverage require data collected with Xdebug. Reports can be generated as HTML, Clover, OpenClover, Cobertura, Crap4J, PHPUnit XML, text, JSONL, or serialized PHP. HTML output includes directory and file views with line-by-line highlighting, plus class, trait, and function views grouped by namespace. You can merge serialized data from separate test runs with phpcov, and its patch-coverage command calculates coverage for changed lines in a unified diff. The library is a first-party PHPUnit dependency and is licensed under BSD-3-Clause. The current package requires PHP 8.4 or later and the DOM, libxml, mbstring, and xmlwriter extensions.
Who it suits
PHP_CodeCoverage suits PHP developers who need coverage measures and reports within a project or development workflow. It requires PHP 8.4 or later and the listed extensions.
What it does well
- Supports multiple coverage measures
- Offers a range of report formats
- HTML reports show line-by-line coverage
- Combines serialized runs and analyzes changed lines
What to know first
- Requires PHP 8.4 or later
- Requires DOM, libxml, mbstring, and xmlwriter
- PCOV provides line coverage only
Limits
PCOV provides line coverage only; branch and path coverage require data collected with Xdebug. The package also requires PHP 8.4 or later and the DOM, libxml, mbstring, and xmlwriter extensions.
Getting started
- Install PHP 8.4 or later with DOM, libxml, mbstring, and xmlwriter
- Add the library with Composer using `composer require phpunit/php-code-coverage`
- Use `composer require --dev phpunit/php-code-coverage` for development-only use
- Choose PCOV for line coverage or Xdebug for line, branch, and path coverage
- Start and stop coverage collection for a named test
- Render the collected data in a selected report format
Verdict
PHP_CodeCoverage provides coverage collection and reporting options for PHP projects, including combined-run and patch analysis. Choose Xdebug data when branch or path coverage is needed.
Questions
Is PHP_CodeCoverage free?
Yes. It is free, open-source software licensed under BSD-3-Clause.
How do I install it?
Add it to a project with Composer using `composer require phpunit/php-code-coverage`. For development-only use, add it with the `--dev` option.
Which coverage types are supported?
It supports line, branch, path, function and method, class and trait coverage, plus the CRAP index.
What report formats can it produce?
Formats include HTML, Clover, OpenClover, Cobertura, Crap4J, PHPUnit XML, text, JSONL, and serialized PHP.
What are the runtime requirements?
The current package requires PHP 8.4 or later and the DOM, libxml, mbstring, and xmlwriter extensions.
What is the difference between PCOV and Xdebug here?
PCOV supports line coverage only. Branch and path coverage require data collected with Xdebug.
Facts from PHP_CodeCoverage's own pages
- Coverage collection
- The usage example starts and stops coverage collection for a named test. · github.com, 11 Oct 2026
- Coverage drivers
- The package suggests PCOV for line coverage and Xdebug for line, branch and path coverage. · github.com, 4 Oct 2026
- Coverage limitation
- The PHPUnit manual says PCOV supports line coverage only; branch and path coverage require data collected with Xdebug. · docs.phpunit.de, 4 Oct 2026
- Coverage metrics
- The PHPUnit manual says the library supports line, branch, path, function and method, class and trait coverage, and the CRAP index. · docs.phpunit.de, 4 Oct 2026
- Development use
- The README recommends adding it as a development-time dependency when it is only needed to run a project's test suite. · github.com, 11 Oct 2026
- HTML reports
- HTML reports provide directory and file views with line-by-line highlighting, plus class, trait and function views organized by namespace. · docs.phpunit.de, 4 Oct 2026
- Installation
- The README shows installation as a per-project dependency with Composer. · github.com, 11 Oct 2026
- Integration
- The repository describes the library as a first-party dependency of PHPUnit. · github.com, 4 Oct 2026
- License
- The repository identifies the library's license as BSD-3-Clause. · github.com, 11 Oct 2026
- Maintainer
- The Composer manifest names Sebastian Bergmann as the lead author. · github.com, 11 Oct 2026
- Parallel runs
- Serialized coverage files from separate test runs can be merged with phpcov to produce a combined report. · docs.phpunit.de, 4 Oct 2026
- Patch analysis
- The phpcov patch-coverage command calculates coverage for changed lines in a unified diff. · docs.phpunit.de, 4 Oct 2026
- PHP requirement
- The Composer manifest requires PHP version 8.4 or later. · github.com, 11 Oct 2026
- Purpose
- The library collects, processes, and renders PHP code coverage information. · github.com, 11 Oct 2026
- Report formats
- The PHPUnit manual lists HTML, Clover, OpenClover, Cobertura, Crap4J, PHPUnit XML, text, JSONL and serialized PHP output. · docs.phpunit.de, 4 Oct 2026
- Report output
- The example renders an OpenClover report from collected coverage data. · github.com, 11 Oct 2026
- Runtime extensions
- The Composer manifest requires the DOM, libxml, mbstring, and xmlwriter PHP extensions. · github.com, 11 Oct 2026
- Runtime requirements
- The current package requires PHP 8.4 or later and the DOM, libxml, mbstring and xmlwriter extensions. · github.com, 4 Oct 2026
- Security policy coverage
- The project states that PHPUnit's security policy also applies to this library because it is a first-party PHPUnit dependency. · github.com, 11 Oct 2026
- Security reporting
- The security policy asks vulnerability reporters to use coordinated disclosure and says not to report vulnerabilities through public GitHub issues, discussions, or pull requests. · github.com, 11 Oct 2026
- Serialized data
- The README shows generating an OpenClover report from serialized coverage data using an unserializer. · github.com, 11 Oct 2026
Where PHP_CodeCoverage stands on Freedom251
- Test Coverage Tools#22 of 27