Code coverage in Pest tells you which lines of code your test suite executes and which lines it doesn’t. Of course, PHPUnit offers you a beautiful section about this topic: Code Coverage Analysis.
If you're running Xdebug you need to make sure that coverage is enabled in Xdebug. The easiest way to do this is to set the
XDEBUG_MODEenvironment variable to
coveragebefore running your tests. e.g.
XDEBUG_MODE=coverage ./vendor/bin/pest --coverage
Now, in this section, we are going to see the extra options that Pest offers.
--coverage option, gives you a human-readable code coverage
directly on the console.
Keep in mind: the percentage displayed concerns the number of lines of source code that has been tested/executed.
Of course, you can always combine the
--min option to configure minimum threshold enforcement
for coverage results. If the thresholds are not met, Pest will return failure.
./vendor/bin/pest --coverage --min=90
By default, the PHPUnit configuration file generated by Pest initialization will include directory coverage for the
Although this covers most libraries and applications, you may need to add more directories to be covered. To do this, you'll need to add a new
<directory> element inside the
If you are experiencing a
Coverage not found in path: vendor/pestphp/.temp/coverage.php exception message, for example, if your code is under a
lib directory, you'll need to apply the following change to your
<coverage processUncoveredFiles="true"> <include> <directory suffix=".php">./app</directory> <directory suffix=".php">./src</directory> + <directory suffix=".php">./lib</directory> </include> </coverage>
Next section: CLI Options →