How to enable XDEBUG coverage mode in LocalWP

blockify Avatar

·

, ,

·

When running PHP unit tests in your LocalWP project you might get this notice from PHPUnit:

Copied!
Runtime: PHP 8.3.0 Configuration: ./phpunit.dist.xml Warning: XDEBUG_MODE=coverage or xdebug.mode=coverage has to be setCode language: HTTP (http)

To fix this and enable coverage mode for XDEBUG, first make sure XDEBUG is enabled for the local site:

Once enabled, click on the “Go to site folder” link from the LocalWP screen to open the site folder in Finder:

From here, open the php.ini.hbs file in a text editor and find the XDEBUG section. It’s usually around line 227. Now simply add ‘coverage’ to the xdebug.mode setting as shown below:

Once coverage mode has been added, restart the Local site to apply the new settings.

Now when you run PHPUnit test you should see:

Copied!
Runtime: PHP 8.3.0 with Xdebug 3.3.0 Configuration: ./phpunit.dist.xmlCode language: HTTP (http)