Skip to content

Commit a7f038c

Browse files
committed
docs: rewrite README with EN/zh-TW, update description and display name
1 parent d7816e5 commit a7f038c

File tree

2 files changed

+195
-2
lines changed

2 files changed

+195
-2
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-phpunit",
3-
"description": "The VS Code PHPUnit Test Explorer extension supports PHPUnit and Pest, enabling test execution in Docker and SSH environments. It integrates with vscode-xdebug for step-by-step debugging within VS Code.",
4-
"displayName": "PHPUnit Test Explorer",
3+
"description": "Run PHPUnit and Pest tests in VS Code with the native Test Explorer. Supports Docker, SSH, Laravel Sail, ParaTest, and Xdebug step-debugging.",
4+
"displayName": "PHPUnit & Pest Test Explorer",
55
"icon": "img/icon.png",
66
"publisher": "recca0120",
77
"version": "3.8.2",

readme.zh-TW.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# PHPUnit & Pest Test Explorer for VS Code
2+
3+
[![Version](https://img.shields.io/vscode-marketplace/v/recca0120.vscode-phpunit.svg?style=flat-square&label=vscode%20marketplace)](https://marketplace.visualstudio.com/items?itemName=recca0120.vscode-phpunit)
4+
[![Downloads](https://img.shields.io/vscode-marketplace/d/recca0120.vscode-phpunit.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=recca0120.vscode-phpunit)
5+
6+
[English](readme.md)
7+
8+
在 VS Code 中使用原生 Test Explorer 執行 PHPUnit 和 Pest 測試。支援 Docker、SSH 等遠端環境,並可搭配 Xdebug 進行逐步偵錯。
9+
10+
![PHPUnit](img/phpunit.gif)
11+
12+
![Pest](img/pest.png)
13+
14+
## 功能特色
15+
16+
- 在側邊欄 Test Explorer 中自動偵測並顯示所有 PHPUnit / Pest 測試
17+
- 執行或偵錯單一測試、檔案、測試套件或整個專案
18+
- 彩色輸出面板,包含語法高亮的測試結果與嵌入式 PHP 原始碼片段
19+
- 錯誤堆疊追蹤中的檔案路徑可直接點擊跳轉
20+
- 支援 PHPUnit 7 – 12 及 Pest 2 – 3
21+
- 支援 ParaTest 平行執行
22+
- 透過自訂命令支援 Docker、SSH 等遠端環境
23+
- 整合 Xdebug 進行逐步偵錯
24+
- 檔案變更時自動持續執行測試
25+
26+
## 指令
27+
28+
| 指令 | 說明 | 預設快捷鍵 |
29+
|---|---|---|
30+
| `phpunit.reload` | 重新載入測試 ||
31+
| `phpunit.run-all` | 執行所有測試 | `Cmd+T Cmd+S` |
32+
| `phpunit.run-file` | 執行目前檔案的測試 | `Cmd+T Cmd+F` |
33+
| `phpunit.run-test-at-cursor` | 執行游標位置的測試 | `Cmd+T Cmd+T` |
34+
| `phpunit.run-by-group` | 依群組執行測試 ||
35+
| `phpunit.rerun` | 重複上次測試 | `Cmd+T Cmd+L` |
36+
37+
## 設定
38+
39+
所有設定皆在 `phpunit.*` 命名空間下,可加入 `.vscode/settings.json`
40+
41+
| 設定 | 類型 | 預設值 | 說明 |
42+
|---|---|---|---|
43+
| `phpunit.php` | `string` | `"php"` | PHP 執行檔路徑。未設定時使用系統 PATH 中的 `php`|
44+
| `phpunit.phpunit` | `string` | `"vendor/bin/phpunit"` | PHPUnit 或 Pest 執行檔路徑。自動從 `vendor/bin`、專案根目錄或系統 PATH 偵測。 |
45+
| `phpunit.command` | `string` | `"${php}" ${phpargs} "${phpunit}" ${phpunitargs}` | 自訂命令範本。可用變數:`${php}``${phpargs}``${phpunit}``${phpunitargs}``${phpunitxml}``${cwd}`|
46+
| `phpunit.args` | `string[]` | `[]` | 傳遞給 PHPUnit 的額外參數(如 `["-c", "phpunit.xml.dist"]`)。 |
47+
| `phpunit.paths` | `object` || 遠端環境的路徑對應(如 `{ "${workspaceFolder}": "/app" }`)。 |
48+
| `phpunit.environment` | `object` || 執行前設定的環境變數(如 `{ "XDEBUG_MODE": "coverage" }`)。 |
49+
| `phpunit.clearOutputOnRun` | `boolean` | `true` | 每次執行前清除輸出面板。 |
50+
| `phpunit.showAfterExecution` | `string` | `"onFailure"` | 何時顯示輸出面板:`"always"``"onFailure"``"never"`|
51+
| `phpunit.debuggerConfig` | `string` || 偵錯測試時使用的 `launch.json` 設定名稱。 |
52+
| `phpunit.xdebugPort` | `integer` | `0` | Xdebug 通訊埠。`0` 表示使用隨機埠。 |
53+
54+
## 設定範例
55+
56+
### 基本使用
57+
58+
PHPUnit 和 Pest 會自動偵測,大部分情況不需要任何設定。
59+
60+
若要明確指定 Pest:
61+
62+
```jsonc
63+
{
64+
"phpunit.phpunit": "vendor/bin/pest"
65+
}
66+
```
67+
68+
### Laravel Artisan
69+
70+
```jsonc
71+
{
72+
"phpunit.phpunit": "artisan test"
73+
}
74+
```
75+
76+
### Laravel Sail
77+
78+
```jsonc
79+
{
80+
"phpunit.command": "docker compose exec -u sail laravel.test ${php} ${phpargs} ${phpunit} ${phpunitargs}",
81+
"phpunit.phpunit": "artisan test",
82+
"phpunit.paths": {
83+
"${workspaceFolder}": "/var/www/html"
84+
}
85+
}
86+
```
87+
88+
### ParaTest
89+
90+
```jsonc
91+
{
92+
"phpunit.phpunit": "vendor/bin/paratest"
93+
}
94+
```
95+
96+
### Docker
97+
98+
```jsonc
99+
{
100+
"phpunit.command": "docker exec -t [container_id] /bin/sh -c \"${php} ${phpargs} ${phpunit} ${phpunitargs}\"",
101+
"phpunit.paths": {
102+
"${workspaceFolder}": "/app"
103+
}
104+
}
105+
```
106+
107+
或使用 `docker run`
108+
109+
```jsonc
110+
{
111+
"phpunit.command": "docker run --rm -t -v ${PWD}:/app -w /app php:latest ${php} ${phpargs} ${phpunit} ${phpunitargs}",
112+
"phpunit.paths": {
113+
"${workspaceFolder}": "/app"
114+
}
115+
}
116+
```
117+
118+
### SSH
119+
120+
```jsonc
121+
{
122+
"phpunit.command": "ssh user@host \"cd /app; ${php} ${phpargs} ${phpunit} ${phpunitargs}\"",
123+
"phpunit.paths": {
124+
"${workspaceFolder}": "/app"
125+
}
126+
}
127+
```
128+
129+
### DDEV
130+
131+
```jsonc
132+
{
133+
"phpunit.command": "ddev exec ${php} ${phpargs} ${phpunit} ${phpunitargs}"
134+
}
135+
```
136+
137+
## Xdebug 偵錯
138+
139+
1.`.vscode/launch.json` 建立偵錯設定:
140+
141+
```jsonc
142+
{
143+
"version": "0.2.0",
144+
"configurations": [
145+
{
146+
"name": "Listen for Xdebug",
147+
"type": "php",
148+
"request": "launch",
149+
"port": 9003,
150+
"pathMappings": {
151+
"/var/www": "${workspaceRoot}"
152+
}
153+
}
154+
]
155+
}
156+
```
157+
158+
2. 在擴充設定中指定該設定名稱:
159+
160+
```jsonc
161+
{
162+
"phpunit.debuggerConfig": "Listen for Xdebug"
163+
}
164+
```
165+
166+
若 Xdebug 設定為 `xdebug.start_with_request=trigger`,需加入觸發變數:
167+
168+
```jsonc
169+
{
170+
"phpunit.command": "docker compose exec -e XDEBUG_TRIGGER=VSCODE app bash -c \"${php} ${phpargs} ${phpunit} ${phpunitargs}\"",
171+
"phpunit.debuggerConfig": "Listen for Xdebug"
172+
}
173+
```
174+
175+
然後在 Test Explorer 中點擊 **Debug Test** 按鈕即可。
176+
177+
## 疑難排解
178+
179+
### `${workspaceFolder}` 在路徑對應中無法正確解析
180+
181+
請將 `${workspaceFolder}` 替換為實際的絕對路徑:
182+
183+
```jsonc
184+
{
185+
"phpunit.paths": {
186+
"/home/user/myproject": "/app"
187+
}
188+
}
189+
```
190+
191+
## 授權
192+
193+
[MIT](LICENSE.md)

0 commit comments

Comments
 (0)