PHP_CodeCoverage is a library that provides collection, processing, and rendering functionality for PHP code coverage information.
PHP 5.6 is required but using the latest version of PHP is highly recommended.
Xdebug is the only source of raw code coverage data supported for PHP 5. Version 2.2.1 of Xdebug is required but using the latest version is highly recommended.
Version 2.4.0 (or later) of Xdebug as well as phpdbg are supported sources of raw code coverage data for PHP 7.
A version of HHVM that implements the Xdebug API for code coverage (xdebug_*_code_coverage()
) is required.
To add PHP_CodeCoverage as a local, per-project dependency to your project, simply add a dependency on phpunit/php-code-coverage
to your project's composer.json
file. Here is a minimal example of a composer.json
file that just defines a dependency on PHP_CodeCoverage 4.0:
{
"require": {
"phpunit/php-code-coverage": "4.0.*"
}
}
<?php
$coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage();
$coverage->start('<name of test>');
// ...
$coverage->stop();
$writer = \SebastianBergmann\CodeCoverage\Report\Clover();
$writer->process($coverage, '/tmp/clover.xml');
$writer = new \SebastianBergmann\CodeCoverage\Report\Html\Facade();
$writer->process($coverage, '/tmp/code-coverage-report');