https://github.com/sebastianbergmann/php-code-coverage
Library that provides collection, processing, and rendering functionality for PHP code coverage information.
https://github.com/sebastianbergmann/php-code-coverage
Last synced: 13 days ago
JSON representation
Library that provides collection, processing, and rendering functionality for PHP code coverage information.
- Host: GitHub
- URL: https://github.com/sebastianbergmann/php-code-coverage
- Owner: sebastianbergmann
- License: bsd-3-clause
- Created: 2009-05-28T16:01:43.000Z (almost 17 years ago)
- Default Branch: main
- Last Pushed: 2026-04-07T09:03:57.000Z (17 days ago)
- Last Synced: 2026-04-09T02:02:34.959Z (16 days ago)
- Language: PHP
- Homepage:
- Size: 69.1 MB
- Stars: 8,932
- Watchers: 51
- Forks: 386
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog-14.0.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- favorite-link - 为 PHP 代码覆盖率信息提供收集,处理和呈现功能的库。
- php-awesome - CodeCoverage - 代码覆盖率报表工具 (类库 / 代码检查/静态分析)
README
# phpunit/php-code-coverage
[](https://packagist.org/packages/phpunit/php-code-coverage)
[](https://github.com/sebastianbergmann/php-code-coverage/actions)
[](https://codecov.io/gh/sebastianbergmann/php-code-coverage)
Provides collection, processing, and rendering functionality for PHP code coverage information.
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
```
composer require phpunit/php-code-coverage
```
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
```
composer require --dev phpunit/php-code-coverage
```
## Usage
### Collecting code coverage data and generating a report
```php
includeFiles(
[
'/path/to/file.php',
'/path/to/another_file.php',
],
);
$coverage = new CodeCoverage(
(new DriverSelector)->forLineCoverage($filter),
$filter,
);
$coverage->start('');
// ...
$coverage->stop();
ReportFacade::fromObject($coverage)->renderOpenClover('/tmp/openclover.xml');
```
### Generating a report from serialized code coverage data
```php
unserialize('/path/to/coverage.php');
ReportFacade::fromSerializedData($data)->renderOpenClover('/tmp/openclover.xml');
```