Chris@0
|
1 [](https://packagist.org/packages/phpunit/php-code-coverage)
|
Chris@0
|
2 [](https://travis-ci.org/sebastianbergmann/php-code-coverage)
|
Chris@0
|
3
|
Chris@0
|
4 # PHP_CodeCoverage
|
Chris@0
|
5
|
Chris@0
|
6 **PHP_CodeCoverage** is a library that provides collection, processing, and rendering functionality for PHP code coverage information.
|
Chris@0
|
7
|
Chris@0
|
8 ## Requirements
|
Chris@0
|
9
|
Chris@0
|
10 PHP 5.3.3 is required but using the latest version of PHP is highly recommended
|
Chris@0
|
11
|
Chris@0
|
12 ### PHP 5
|
Chris@0
|
13
|
Chris@0
|
14 [Xdebug](http://xdebug.org/) is the only source of raw code coverage data supported for PHP 5. Version 2.1.3 of Xdebug is required but using the latest version is highly recommended.
|
Chris@0
|
15
|
Chris@0
|
16 ### PHP 7
|
Chris@0
|
17
|
Chris@0
|
18 [phpdbg](http://phpdbg.com/docs) is currently the only source of raw code coverage data supported for PHP 7. Once Xdebug has been updated for PHP 7 it, too, will be supported.
|
Chris@0
|
19
|
Chris@0
|
20 ### HHVM
|
Chris@0
|
21
|
Chris@0
|
22 A version of HHVM that implements the Xdebug API for code coverage (`xdebug_*_code_coverage()`) is required.
|
Chris@0
|
23
|
Chris@0
|
24 ## Installation
|
Chris@0
|
25
|
Chris@0
|
26 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 2.0:
|
Chris@0
|
27
|
Chris@0
|
28 {
|
Chris@0
|
29 "require": {
|
Chris@0
|
30 "phpunit/php-code-coverage": "^2"
|
Chris@0
|
31 }
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 ## Using the PHP_CodeCoverage API
|
Chris@0
|
35
|
Chris@0
|
36 ```php
|
Chris@0
|
37 <?php
|
Chris@0
|
38 $coverage = new PHP_CodeCoverage;
|
Chris@0
|
39 $coverage->start('<name of test>');
|
Chris@0
|
40
|
Chris@0
|
41 // ...
|
Chris@0
|
42
|
Chris@0
|
43 $coverage->stop();
|
Chris@0
|
44
|
Chris@0
|
45 $writer = new PHP_CodeCoverage_Report_Clover;
|
Chris@0
|
46 $writer->process($coverage, '/tmp/clover.xml');
|
Chris@0
|
47
|
Chris@0
|
48 $writer = new PHP_CodeCoverage_Report_HTML;
|
Chris@0
|
49 $writer->process($coverage, '/tmp/code-coverage-report');
|
Chris@0
|
50 ```
|