If you're after code coverage display, pcov is a great choice. However, with Laravel Herd, you'll have to install pcov manually.
Luckily, it's not to tricky. Let's get started.
I'd recommend checking to see if pcov is installed or not first (incase it's been misconfigured). We'll run this command at the end of the steps to verify we have it installed too.
php -m | grep pcov
php -m
lists modules, and grep just searches for pcov
.
If you see no output here — great, as expected it's not installed.
Using Homebrew, install pcov. Ensure you match up the version of PHP you're using (in my case, PHP 8.3).
brew install shivammathur/extensions/pcov@8.3
If you were using PHP 8.2, you'd run this:
brew install shivammathur/extensions/pcov@8.2
Next up, find the pcov.so extension. Because we've used Homebrew, it'll likely be within the /opt/homebrew/Cellar/pcov@8.3
directory.
Inside this directory, you'll find a version number, so the full path would be /opt/homebrew/Cellar/pcov@8.3/1.0.12/pcov.so
. Make sure you've found this on your machine and noted down the full path to the pcov.so
file. You'll need that next.
From your Laravel Herd menu, select Open configuration files and then open 83/php.ini
in your editor of choice. It'll look something like this:
curl.cainfo=/Users/alexgs/Library/Application Support/Herd/config/php/cacert.pem
openssl.cafile=/Users/alexgs/Library/Application Support/Herd/config/php/cacert.pem
pcre.jit=0
memory_limit=400000M
upload_max_filesize=2000000M
auto_prepend_file=/Applications/Herd.app/Contents/Resources/valet/dump-loader.php
extension=/Applications/Herd.app/Contents/Resources/herd-ext/herd-83-arm64.so
Add the pcov.so
file as an extension:
curl.cainfo=/Users/alexgs/Library/Application Support/Herd/config/php/cacert.pem
openssl.cafile=/Users/alexgs/Library/Application Support/Herd/config/php/cacert.pem
pcre.jit=0
memory_limit=400000M
upload_max_filesize=2000000M
auto_prepend_file=/Applications/Herd.app/Contents/Resources/valet/dump-loader.php
extension=/Applications/Herd.app/Contents/Resources/herd-ext/herd-83-arm64.so
extension=/opt/homebrew/Cellar/pcov@8.3/1.0.12/pcov.so
On the command line, run:
herd restart
This will restart all Herd services and reload php.ini
. You can also choose Stop all and Start all from the Herd menu if you prefer.
Back to the command we ran earlier, list all your PHP modules and grep for pcov.
php -m | grep pcov
If you see pcov
output, you're done! Execute your test runner with --coverage
and everything should work nicely.
pest --coverage
Happy testing!