Laravel - HTML Test Coverage Report
Irving Gomez | | Backend
HTML Test Coverage Report
In this tutorial I will be showing you how to set up test coverage reporting in Laravel with an HTML document output. This tutorial assumes you have a working PHP installation. Commands are being ran inside your Laravel projects main directory.
- Installing XDebug
- Edit PHP.ini
- If you don't know where your php file is, this command calls the PHP binary, and tells it to give us our configuration paths.
php --ini
- Look for the line with "Loaded Configuration File:" and open it with your favorite editor, or with vim. In my environment, the INI file is located here.
/usr/local/etc/php/8.3/php.ini
- You can find the file in your Finder by pressing
COMMAND + SHIFT + G
and in the path input, type in or paste the INI location or use vimvim /usr/local/etc/php/8.3/php.ini
. - Add the following line to the end of the file. This tells XDebug to turn on the following features.
xdebug.mode=develop,coverage,debug,gcstats,profile,trace
- Generating the report
- To generate the report, we need to call the test command, and include some extra coverage options.
php artisan test --coverage --coverage-html=./.cov
- Results
- To view the HTML files, open the index file in chrome.
open ./.cov/index.html
That is it! You now have your test coverage report inside of your browser for easy viewing and navigation.