phpunit/php-code-coverage's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
phpunit/php-code-coverage is a robust and versatile PHP library, providing the essential functions for collection, processing, and rendering of PHP code coverage information. Code coverage is a key measure used in software testing to describe the degree to which the source code of a program is tested by a particular test suite. The library collects the data and renders the information so it can be used by developers to improve their code and testing.
Utilizing phpunit/php-code-coverage is straightforward for anyone familiar with PHP and composer packages. Installation is completed through Composer by running the following command providing the package as a local per-project dependency:
composer require phpunit/php-code-coverage
For installation as a development-time dependency, which might be required to run a project's test suite, you should add it as follows:
composer require --dev phpunit/php-code-coverage
Here's a basic usage sample for phpunit/php-code-coverage in your PHP script:
<?php declare(strict_types=1); use SebastianBergmann\CodeCoverage\Filter; use SebastianBergmann\CodeCoverage\Driver\Selector; use SebastianBergmann\CodeCoverage\CodeCoverage; use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport; $filter = new Filter; $filter->includeFiles(['/path/to/file.php', '/path/to/another_file.php']); $coverage = new CodeCoverage( (new Selector)->forLineCoverage($filter), $filter ); $coverage->start('<name of test>'); // Execute your test code here... $coverage->stop(); (new HtmlReport)->process($coverage, '/tmp/code-coverage-report');
In the above code snippet, the library is used to start coverage, execute test code within the start/stop block, and then process the coverage data into HTML report format.
The comprehensive documentation of phpunit/php-code-coverage can be reached through the repository on GitHub at sebastianbergmann/php-code-coverage. The repository contains thorough explanations and additional usage examples for various functions and interfaces offered by the library.