英文:
How to have PHPUnit/Xdebug ignore 'Could not connect to debugging client'
问题
我已经配置好本地的PHP以运行Xdebug。
但我并不总是把我的IDE打开以监听Xdebug。在这种情况下,我可以从浏览器加载网页并运行CLI PHP脚本而无任何问题,除了PHPUnit,它会出现以下错误:
Xdebug: [Step Debug] 无法连接到调试客户端。尝试过:localhost:9003(通过xdebug.client_host/xdebug.client_port)
我该如何让PHPUnit或Xdebug忽略这个错误?
我不想一直重新启动PHP来打开和关闭Xdebug,也不想修改浏览器或环境变量来告诉Xdebug是否要运行。
英文:
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.
答案1
得分: 3
您之所以收到此错误是因为您要求Xdebug与您的IDE通信。如果它无法执行此操作,您将收到此警告。这是一个功能。
两个选项:
- 如果需要启用代码覆盖率,您可以在
phpunit
前面加上XDEBUG_MODE=off
或XDEBUG_MODE=coverage
:XDEBUG_MODE=coverage phpunit …extra_params…
- 在您的PHP ini文件中配置Xdebug的日志文件:
xdebug.log=/tmp/xdebug.log
,在这种情况下,警告将记录在日志文件中。
英文:
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:
- You can prefix your
phpunit
withXDEBUG_MODE=off
orXDEBUG_MODE=coverage
if you need code coverage enabled:XDEBUG_MODE=coverage phpunit …extra_params…
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论