[英]How can I get XDebug to run with PHPUnit on the CLI in Windows using VSCode?
我運行了這個命令:
"C:\\xampp\\php\\.\\php.exe" "C:\\xampp\\php\\phpunit" -d xdebug.profiler_enable=on -d xdebug.idekey=VSCODE
C:\\xampp\\php\\php.ini 有以下內容:
[XDebug]
zend_extension = "C:\xampp\php\ext\php_xdebug-2.5.0-7.1-vc14.dll"
xdebug.idekey=VSCODE
xdebug.profiler_enable=1
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
如果我在沒有 Listen for XDebug 的情況下運行命令,我將在命令行窗口中看到以下內容:
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 3.7.21 by Sebastian Bergmann.
Configuration read from C:\xampp\apps\summit\htdocs\wp-content\plugins\hl-market-tracker\phpunit.xml.dist
...
我進入 VSCode 並監聽 XDebug,當我運行命令時,我看到請求 1 和 2 出現在調用堆棧中,但沒有運行單元測試(它似乎掛在某處,因為Installing...
甚至沒有出現在命令行窗口中)。 如果我停止偵聽 Xdebug,我會在調試控制台中看到read ECONNRESET
,然后我會看到Running as single site...
語句被打印出來(但不是正在打印的read ECONNRESET
Installing...
語句)
問題:
我想了解當我嘗試運行單元測試時如何讓調試工作?
為什么我會看到上面描述的掛起行為? 我不明白什么?
參考資料:
對#2 的回答: https : //github.com/felixfbecker/vscode-php-debug/issues/164 :所描述的根本問題是,當運行兩個 php 進程時,它混淆了 VS Code 的調試器。 當我讀到這里時,我想是因為每當運行 php 時,它都會從 php.ini 中讀取,並且該文件告訴 xdebug 偵聽端口 9000,這就是為什么如果運行兩個 php 進程,XDebug 會感到困惑。 從那以后,我看到 phpunit 使用 phpunit 選項啟動 php。 然后我想用不同的遠程端口啟動這個特定的 php,看看它是否解決了掛起問題,它確實解決了。
對 #1 的回答:所以,在 VS Code 的 launch.json 中,
a. 添加另一個配置以在另一個端口 (8000) 上偵聽 XDebug
"name": "PHPUnit",
"type": "php",
"request": "launch",
"port": 8000
灣從命令行啟動時使用此命令
"C:\xampp\php\.\php.exe" -d xdebug.remote_port=8000 "C:\xampp\php\phpunit"
或者,在 phpunit.bat 中更改它以便能夠在命令行中輸入 phpunit
注意事項:
FWIW - 在 launch.json 中設置以下內容適用於 Ubuntu(通過 apt 安裝 XDebug):
"configurations": [
{
"name": "Launch Unit Tests",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"cwd": "${workspaceFolder}",
"env": {
"XDEBUG_CONFIG": "idekey=VSCODE remote_enable=1 profile_enable=1"
},
"args": [
// "--filter",
// "testCanCreateValid"
],
"port": 9000
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.