How To Generate Code Coverage on Laravel Homestead

How To Generate Code Coverage on Laravel Homestead


Sep 04 2017, 20:51 in Web Development

TDD is cool right ? PHPUnit implementation in Laravel is so great that it makes TDD even cooler.

When building your application you may wonder : did I test everything ?? And how can I make sure that everything is tested ?

That's where PHPUnit Code Coverage is fantastic.

In Laravel Homestead however it is not that easy to setup. Running phpunit --coverage-html testReport/ will probably give you an error at first. What you need is to install XDebug !

Let's do that :

sudo apt-get update && sudo apt-get upgrade && sudo apt-get install php-xdebug

Now edit Xdebug config file...

sudo nano /etc/php/7.1/fpm/conf.d/20-xdebug.ini

And make sure you have this setup :

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 250

Finally, restart and activate !

sudo service php7.0-fpm restart

sudo phpenmod -s cli xdebug

Now everything should be good ;)


Share:
Like:

Disable AdBlock on this domain and offer me a cup of coffee :)