From zenbu-powers
處理 Given/When 步驟中執行寫入操作(Command)的 handler 參考文件。觸發關鍵字:已訂閱、已建立、已新增、更新、建立、刪除、提交。 非 user-invocable,由 /aibdd.auto.php.it.red 在實作測試方法時載入。
npx claudepluginhub zenbuapps/zenbu-powers --plugin zenbu-powersThis skill uses the workspace's default tool permissions.
本 handler 適用於呼叫 **Service 寫入方法** 的步驟:
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.
本 handler 適用於呼叫 Service 寫入方法 的步驟:
關鍵字(Given):已訂閱、已建立、已新增、已更新、已刪除
關鍵字(When):更新、建立、新增、刪除、提交、取消、完成
直接呼叫 $this->services->xxx->method(...):
$this->lastError| 項目 | Command | Query |
|---|---|---|
| 系統狀態 | 修改 | 不修改 |
| Service 方法 | updateXxx、createXxx、deleteXxx、subscribeXxx | getXxx、findXxx、listXxx |
| 儲存位置 | $this->lastError(失敗時) | $this->queryResult |
| 驗證方式 | 由 success-failure handler | 由 readmodel-then handler |
另與 aggregate-given 的差異:aggregate-given 透過 Repository.save() 建立資料(fixture),command 則呼叫 Service 觸發完整業務流程。
$this->ids 取得依賴 ID:$userId = $this->ids['Alice'];api.yml 的 operationId(camelCase)。\Throwable 存入 $this->lastError。Given 用戶 "Alice" 已訂閱課程 1
$userId = $this->ids['Alice'];
$this->services->subscription->subscribe($userId, 1);
Given 用戶 "Alice" 已建立訂單 "ORD-001",包含商品 "PROD-001" 數量 2
$userId = $this->ids['Alice'];
$orderId = $this->services->order->create($userId, [
['productId' => 'PROD-001', 'quantity' => 2],
]);
$this->ids['ORD-001'] = $orderId;
When 用戶 "Alice" 更新課程 1 的影片進度為 80%
$userId = $this->ids['Alice'];
try {
$this->services->lesson->updateVideoProgress($userId, 1, 80);
} catch (\Throwable $e) {
$this->lastError = $e;
}
When 用戶 "Alice" 提交訂單
$userId = $this->ids['Alice'];
try {
$this->services->order->submit($userId);
} catch (\Throwable $e) {
$this->lastError = $e;
}
When 管理者建立以下商品:
| 商品 ID | 名稱 | 價格 |
| PROD-001 | iPhone 16 | 30000 |
| PROD-002 | MacBook | 60000 |
$products = [
['商品 ID' => 'PROD-001', '名稱' => 'iPhone 16', '價格' => 30000],
['商品 ID' => 'PROD-002', '名稱' => 'MacBook', '價格' => 60000],
];
try {
foreach ($products as $row) {
$this->services->product->create(
id: $row['商品 ID'],
name: $row['名稱'],
price: (int) $row['價格'],
);
}
} catch (\Throwable $e) {
$this->lastError = $e;
}
所有 Test class 均繼承此基類:
abstract class IntegrationTestCase extends \Yoast\WPTestUtils\WPIntegration\TestCase
{
protected ?\Throwable $lastError = null;
protected mixed $queryResult = null;
protected array $ids = [];
protected object $repos;
protected object $services;
abstract protected function configure_dependencies(): void;
public function set_up(): void {
parent::set_up();
$this->lastError = null;
$this->queryResult = null;
$this->ids = [];
$this->repos = new \stdClass();
$this->services = new \stdClass();
$this->configure_dependencies();
}
}
$this->lastError。$this->ids 取得依賴 ID,禁止硬編或另行查詢。api.yml 的 operationId(camelCase)。$wpdb 或 Repository 繞過 Service。assert_operation_* 驗證。$this->ids 取得$wpdb 或 Repository 呼叫(該層屬 aggregate-given)