phpunit/php-code-coverage
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
nikic/php-parser | v4.17.1 | - | BSD-3-Clause | prod | |
phpunit/php-file-iterator | 4.1.0 | 9.41 kB | BSD-3-Clause | prod | |
phpunit/php-text-template | 3.0.1 | 7.22 kB | BSD-3-Clause | prod | |
sebastian/code-unit-reverse-lookup | 3.0.0 | 6.1 kB | BSD-3-Clause | prod | |
sebastian/complexity | 3.1.0 | 11.36 kB | BSD-3-Clause | prod | |
sebastian/environment | 6.0.1 | 9.41 kB | BSD-3-Clause | prod | |
sebastian/lines-of-code | 2.0.1 | 9.52 kB | BSD-3-Clause | prod | |
sebastian/version | 4.0.1 | 5.02 kB | BSD-3-Clause | prod | |
theseer/tokenizer | 1.2.2 | - | BSD-3-Clause | prod |
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.