This post assumes you’re familiar with Laravel’s Homestead VM.
Problem
You want to generate PHPUnit code coverage reports and you’re developing on Homestead VM.
Solution
Add a function to the Homestead aliases file
function code_coverage() {change to the code directory
cd code;xon;phpunit --coverage-html ./public/reports/tests;xoff
}
xon/xoff enable/disable xdebug
Generated coverage reports are written to public/reports/tests directory
Re-provision Homestead VM
$vagrant halt
$vagrant up --provision
Add this function to your .zshrc
function code_coverage() {
vagrant ssh -- -t 'bash -ic "code_coverage"'
chrome ./public/reports/tests/index.html
}
This function connects to the Homestead VM and calls the code_coverage function on the VM writing results to …/tests/index.html which we open up in Chrome. That’s it.