From zenbu-powers
PHP IT 全自動批次迴圈。掃描 features 目錄,為每個 .feature 展開完整的 4 phase TODO 清單 (test-skeleton → red → green → refactor),然後逐一執行直到全數完成。 專注 WordPress plugin 整合測試。 當 /aibdd-specformula 的 Phase 02 觸發,或使用者說「php it control-flow」「批次執行」時觸發。
npx claudepluginhub zenbuapps/zenbu-powers --plugin zenbu-powersThis skill uses the workspace's default tool permissions.
本 skill 為 **WordPress PHP 整合測試自動化流程** 的 **主控調度器**。
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Checks Next.js compilation errors using a running Turbopack dev server after code edits. Fixes actionable issues before reporting complete. Replaces `next build`.
Guides code writing, review, and refactoring with Karpathy-inspired rules to avoid overcomplication, ensure simplicity, surgical changes, and verifiable success criteria.
Share bugs, ideas, or general feedback.
本 skill 為 WordPress PHP 整合測試自動化流程 的 主控調度器。
職責:
specs/features/ 中所有 .feature 檔案觸發條件:
/zenbu-powers:aibdd-specformula 的 Phase 02 自動調用/zenbu-powers:aibdd.auto.php.it.control-flow對每個 Feature 檔案:
Phase 1: /zenbu-powers:aibdd.auto.php.it.test-skeleton (PHPUnit 測試骨架 + TODO 註解)
↓
Phase 2: /zenbu-powers:aibdd.auto.php.it.red (紅燈:Stub + Test 實作)
↓
Phase 3: /zenbu-powers:aibdd.auto.php.it.green (綠燈:WP DB Repository + Service 邏輯)
↓
Phase 4: /zenbu-powers:aibdd.auto.php.it.refactor (重構:消除重複、改名、抽 helper)
必須依序執行,不可跳過、不可顛倒。
在展開 TodoWrite 之前,檢查下列檔案 / 設定:
| 檢查項 | 路徑 | 若缺失 |
|---|---|---|
| wp-env 設定 | .wp-env.json | 提示使用者建立,說明 plugin 路徑 |
| PHPUnit 設定 | phpunit.xml.dist | 須有 <testsuite name="integration"> 節 |
| 測試 bootstrap | tests/bootstrap.php | 須載入 Yoast WPTestUtils |
| Composer 依賴 | composer.json | 須含 yoast/wp-test-utils |
| IntegrationTestCase | tests/integration/IntegrationTestCase.php | 告知將由 red 階段自動建立 |
phpunit.xml.dist 片段<?xml version="1.0"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="integration">
<directory suffix="Test.php">./tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
tests/bootstrap.php 片段<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
\Yoast\WPTestUtils\WPIntegration\bootstrap_it();
composer.json require-dev 片段"require-dev": {
"phpunit/phpunit": "^9.6",
"yoast/wp-test-utils": "^1.2"
}
若任一必要項缺失,停下並提示使用者補齊。IntegrationTestCase.php 例外 — 告知「將由 /zenbu-powers:aibdd.auto.php.it.red 自動建立」即可繼續。
${FEATURES_DIR} 環境變數,fallback 到 specs/features/Glob 工具搜尋 **/*.feature${FEATURES_DIR}/句型.md 存在 → 依其中列出的 feature 順序01-lesson-progress.feature、02-course-enrollment.feature)以控制順序將排序後清單呈現給使用者:
偵測到 3 個 feature 檔案,將依下列順序執行:
1. specs/features/01-lesson-progress.feature
2. specs/features/02-course-enrollment.feature
3. specs/features/03-order-checkout.feature
按順序執行?(y/n)
對每個 feature 展開 4 個任務,依 phase 順序排列:
TodoWrite([
{ content: "01-lesson-progress — Test Skeleton", status: "pending" },
{ content: "01-lesson-progress — Red", status: "pending" },
{ content: "01-lesson-progress — Green", status: "pending" },
{ content: "01-lesson-progress — Refactor", status: "pending" },
{ content: "02-course-enrollment — Test Skeleton", status: "pending" },
{ content: "02-course-enrollment — Red", status: "pending" },
{ content: "02-course-enrollment — Green", status: "pending" },
{ content: "02-course-enrollment — Refactor", status: "pending" },
...
])
展開規則:先橫向展開單一 feature 的 4 phase,再進入下一個 feature。確保同一 feature 的 4 phase 連續執行。
取下一個 pending 任務
↓
標記 → in_progress
↓
使用 Skill 工具呼叫對應 skill(傳入 feature file 絕對路徑)
↓
等待完成
↓
標記 → completed
↓
前進到下一個 pending(若有)
| 任務 Phase | 呼叫的 Skill | 傳入參數 |
|---|---|---|
| Test Skeleton | /zenbu-powers:aibdd.auto.php.it.test-skeleton | feature file 絕對路徑 |
| Red | /zenbu-powers:aibdd.auto.php.it.red | feature file 絕對路徑 |
| Green | /zenbu-powers:aibdd.auto.php.it.green | feature file 絕對路徑 |
| Refactor | /zenbu-powers:aibdd.auto.php.it.refactor | feature file 絕對路徑 |
// 目前: 01-lesson-progress — Test Skeleton [in_progress]
Skill /zenbu-powers:aibdd.auto.php.it.test-skeleton specs/features/01-lesson-progress.feature
→ 完成:LessonProgressTest.php 建立 + TODO 註解
→ 標記 completed
// 前進到: 01-lesson-progress — Red [pending → in_progress]
Skill /zenbu-powers:aibdd.auto.php.it.red specs/features/01-lesson-progress.feature
→ 完成:Stub 建立 + Test 實作 + 紅燈驗證
→ 標記 completed
// 前進到: 01-lesson-progress — Green [pending → in_progress]
...
所有 TodoWrite 任務皆 completed 後執行:
vendor/bin/phpunit --testsuite integration
或透過 wp-env:
npx wp-env run tests-cli --env-cwd=wp-content/plugins/{plugin} \
vendor/bin/phpunit --testsuite integration
| 面向 | PHP IT | Java / Python |
|---|---|---|
| Phase 數量 | 4 phase(多 test-skeleton) | 3 phase(red / green / refactor) |
| 骨架來源 | 需額外 /zenbu-powers:aibdd.auto.php.it.test-skeleton 產生 PHPUnit 骨架 | BDD 框架(Cucumber / Behave)自動對映 .feature |
| Variant routing | 無 arguments.yml 路由(PHP IT 獨立運作) | 有 IT / API / E2E 分流 |
| 測試命令 | vendor/bin/phpunit | Maven mvn verify / behave |
| DB rollback | WP_UnitTestCase 自動處理 | Testcontainers 手動管理 / Python fixture |
| 基類 | Yoast\WPTestUtils\WPIntegration\TestCase | JUnit 5 / pytest |
| 症狀 | 原因 | 解法 |
|---|---|---|
wp-env: command not found | wp-env 未安裝 | npm install -g @wordpress/env |
Error: Could not start wp-env | Docker 未啟動 / port 衝突 | 啟動 Docker Desktop;檢查 8888 / 8889 port |
Fatal error: Class 'Yoast\WPTestUtils\...' | Yoast WPTestUtils 未安裝 | composer require --dev yoast/wp-test-utils |
No tests executed | phpunit.xml.dist 的 testsuite 路徑錯誤 | 檢查 <directory suffix="Test.php"> 指向 tests/integration |
Error establishing a database connection | wp-env 未啟動 | npx wp-env start |
Class App\... not found | autoload 未更新 | composer dump-autoload |
| Test 卡在 BadMethodCallException | Green phase 未完成 | 檢查 TodoWrite 是否漏標 completed |
開始時輸出:
=== PHP IT Control Flow 啟動 ===
偵測到 N 個 feature 檔案:
1. ...
2. ...
將展開 (N × 4) 個任務,依序執行 test-skeleton → red → green → refactor。
環境檢查:✅ wp-env / ✅ phpunit.xml.dist / ✅ bootstrap.php / ✅ composer deps
開始執行 Phase 1 of (N × 4)...
結束時輸出:
=== PHP IT Control Flow 完成 ===
處理 N 個 feature,共 M 個 test method,全部綠燈。
最終回歸:vendor/bin/phpunit --testsuite integration → PASS