François' Blog

PHPUnit and Xdebug

2017-01-12

Having the Xdebug PHP extension always loaded slows down Composer and Phan.

But I do want to have Xdebug enabled for generating code coverage reports using PHPUnit.

It took me some time to figure this out, and it is not so hard.

First step: install the Xdebug extension, on Fedora:

$ sudo dnf -y install php-pecl-xdebug

Edit the file /etc/php.d/15-xdebug.ini to disable loading the extension:

;zend_extension=xdebug.so

Now, to enable this extension just for running PHPUnit:

$ php -dextension=/usr/lib64/php/modules/xdebug.so /usr/bin/phpunit \
    --coverage-html coverage

To automate this, add the following alias to your $HOME/.bashrc:

alias phpunit="/usr/bin/php -dextension=/usr/lib64/php/modules/xdebug.so /usr/bin/phpunit"

It was surprisingly hard to figure this out, hope it helps someone!

Return to Index