gitmyhub

php-code-coverage

PHP ★ 8.9k updated 2d ago

Library that provides collection, processing, and rendering functionality for PHP code coverage information.

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.

PHPComposerPHPUnitsetup: easycomplexity 2/5

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.

Where it fits