【发布时间】:2019-12-29 09:32:05
【问题描述】:
我最近配置了 VS 代码来使用 xdebug 调试 PHP。它可以可靠地与我的应用程序代码一起工作,但是当我使用 PHPunit 运行单元测试时,我的断点会被忽略。
我的服务器在一个 vagrant box 中运行。
我的php.ini 文件包含以下几行:
[xdebug]
zend_extension="/usr/lib/xdebug/xdebug-2.2.7/modules/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_autostart=1
我使用PHP Debug VS Code 扩展。
这是我的launch.json 配置:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": {
"/var/www/mysite.local/": "${workspaceFolder}"
},
"port": 9000,
"log": true
}
我的单元测试运行良好,例如,在/var/www/mysite.local 内,我可以运行:
phpunit --filter myTestMethod path/to/my/test/file/myTest.php
但是当测试将运行时,我在测试本身中的断点始终被忽略,我无法弄清楚原因。
有人遇到过类似的问题吗?在正常的应用程序请求和单元测试的上下文中调试的工作方式有区别吗?
【问题讨论】:
-
我认为
xdebug.log可能更具解释性。将xdebug.remote_log=xdebug.log添加到您的xdebug 配置中并尝试再次调试phpunit 测试。然后编辑您的问题并将xdebug.log放入您的答案中。xdebug.log将位于项目的根目录中。
标签: php visual-studio-code phpunit vscode-debugger