Search code examples
phpunitphpstorm

PhpStorm: "Run with coverage" results in "Cannot load Xdebug - extension already loaded"


I just upgraded my PhpStorm project from PHPUnit 4.x to PHPUnit 5.x. Running my unit tests works fine.

In order to get "run with coverage" working, I had to edit my Run/Debug configuration and add --whitelist=/path/to/whitelisted/dir to Test Runner options. Now coverage is generated when I choose "Run with coverage," but I get this Xdebug warning.

Testing started at 12:06 PM ...
/usr/local/opt/php56/bin/php -dzend_extension=/usr/local/opt/php56-
xdebug/xdebug.so -dxdebug.coverage_enable=1 
/Users/bwood/code/php/WpsConsole/vendor/phpunit/phpunit/phpunit --
whitelist=/Users/bwood/code/php/WpsConsole/src --coverage-clover /Users/bwood/Library/Caches/PhpStorm2017.3/coverage/WpsConsole$NEW.coverage --no-configuration /Users/bwood/code/php/WpsConsole/tests/UnitTests --teamcity

Cannot load Xdebug - extension already loaded
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

I think the issue is that php is being called with

-dzend_extension=/usr/local/opt/php56-xdebug/xdebug.so

But I can't figure out where I can remove that option. I'm testing a console application so there is no webserver configuration.


Solution

  • Check your PHP Interpreter in PhpStorm -- there is a separate field for xdebug extension. It allows you to not to have xdebug loaded in actual php.ini (so the ordinary script execution will be faster) and only load xdebug when needed (debug/coverage).

    Based on your info so far you have it in php.ini and there. Proposed solution is to remove it from that field.

    enter image description here

    P.S. Obviously, it works for CLI stuff only and dopes not affect browser based debug in any way (as it's web server that runs PHP so IDE cannot pass such parameter there).