PHPUnit/Xdebug 忽略 ‘Could not connect to debugging client’ 的方法是什么?

huangapple go评论49阅读模式
英文:

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 忽略 ‘Could not connect to debugging client’ 的方法是什么?

我该如何让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) PHPUnit/Xdebug 忽略 ‘Could not connect to debugging client’ 的方法是什么?

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通信。如果它无法执行此操作,您将收到此警告。这是一个功能

两个选项:

  1. 如果需要启用代码覆盖率,您可以在phpunit前面加上XDEBUG_MODE=offXDEBUG_MODE=coverageXDEBUG_MODE=coverage phpunit …extra_params…
  2. 在您的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:

  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.

huangapple
  • 本文由 发表于 2023年6月26日 21:15:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定