Search code examples
phpunitxdebug

How to have PHPUnit/Xdebug ignore 'Could not connect to debugging client'


I have my local PHP configured to run Xdebug.

But I don't always have my IDE turned on to listen for Xdebug. When that's the case, I can load web pages from my browser and run CLI PHP scripts without any problems - except for PHPUnit, which fails the test with this:

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

How do I make PHPUnit or Xdebug ignore this error?

I don't want to have to keep restarting PHP to turn Xdebug on and off, and I don't want to have to fiddle with my browser or with environment variables to tell Xdebug whether to run or not.


Solution

  • You're getting this error because you ask Xdebug to talk to your IDE. If it can't do that, you get this warning. That is a feature.

    Two options:

    1. You can prefix your phpunit with XDEBUG_MODE=off or XDEBUG_MODE=coverage if you need code coverage enabled: XDEBUG_MODE=coverage phpunit …extra_params…
    2. Configure Xdebug's log file in your PHP ini file(s): xdebug.log=/tmp/xdebug.log, in which case the warning goes into the log file.