You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

3 years ago
  1. # phpunit/php-code-coverage
  2. [![Latest Stable Version](https://poser.pugx.org/phpunit/php-code-coverage/v/stable.png)](https://packagist.org/packages/phpunit/php-code-coverage)
  3. [![CI Status](https://github.com/sebastianbergmann/php-code-coverage/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/php-code-coverage/actions)
  4. [![Type Coverage](https://shepherd.dev/github/sebastianbergmann/php-code-coverage/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/php-code-coverage)
  5. Provides collection, processing, and rendering functionality for PHP code coverage information.
  6. ## Installation
  7. You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
  8. ```
  9. composer require phpunit/php-code-coverage
  10. ```
  11. 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:
  12. ```
  13. composer require --dev phpunit/php-code-coverage
  14. ```
  15. ## Usage
  16. ```php
  17. <?php declare(strict_types=1);
  18. use SebastianBergmann\CodeCoverage\Filter;
  19. use SebastianBergmann\CodeCoverage\Driver\Selector;
  20. use SebastianBergmann\CodeCoverage\CodeCoverage;
  21. use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlReport;
  22. $filter = new Filter;
  23. $filter->includeDirectory('/path/to/directory');
  24. $coverage = new CodeCoverage(
  25. (new Selector)->forLineCoverage($filter),
  26. $filter
  27. );
  28. $coverage->start('<name of test>');
  29. // ...
  30. $coverage->stop();
  31. (new HtmlReport)->process($coverage, '/tmp/code-coverage-report');
  32. ```