PHPUnit is integrated with PHPCoverage and can generate test coverage reports directly from the command line while 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 the code coverage driver.

> apt install php7.4 - pcov

Then install the PCoV code package

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

With all the basic installation done, you can start generating test reports from the command line

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

The –coverage-html option tells PHPUnit which folder to put the generated HTML files in — the coverage-filter option tells PHPUnit to analyze the code under which folder

The generated coverage report is shown in the figure below:

Reference:


https://www.lambdatest.com/bl…