Home  >  Article  >  Backend Development  >  How to generate code coverage report using PHPUnit?

How to generate code coverage report using PHPUnit?

藏色散人
藏色散人forward
2021-07-12 11:54:292884browse

How to generate code coverage report using PHPUnit?

How to generate code coverage report with PHPUnit?

PHPUnit integrates PHPCoverage and can generate test coverage reports directly through the command line when running tests.

Previous versions of PHPUnit also required the xdebug plug-in to generate reports, but after PHPUnit 8x, you can install the PCOV plug-in as a code coverage driver.

> apt install php7.4-pcov

Then install the pcov code package

> composer require --dev pcov/clobber:^2.0

This completes all the basic installation, and then starts to generate the test report using the command line

> ./vendor/bin/phpunit --coverage-html tests/html --coverage-filter app/models --bootstrap tests/bootstrap.php tests/model/video/block

--coverage- The html option tells phpunit which folder to store the generated html files
--the coverage-filter option tells phpunit which folder to analyze the code under which folder

generated The coverage report is as shown in the figure:

Quote:
https://www.lambdatest.com/blog/phpunit-code-coverage-report-html/

Recommended Study: "PHP Video Tutorial"

The above is the detailed content of How to generate code coverage report using PHPUnit?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete