From zenbu-powers
處理 Then 步驟中驗證 Query 回傳結果($this->queryResult)的 handler 參考文件。觸發關鍵字:查詢結果應、應包含、第 X 個應為。 非 user-invocable,由 /aibdd.auto.php.it.red 在實作測試方法時載入。
npx claudepluginhub zenbuapps/zenbu-powers --plugin zenbu-powersThis skill uses the workspace's default tool permissions.
本 handler 適用於 **Then** 步驟中驗證「已執行 Query 的結果」:
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 適用於 Then 步驟中驗證「已執行 Query 的結果」:
關鍵字:查詢結果應、應包含、第 X 個應為、應為空
讀取 $this->queryResult 進行欄位/屬性斷言。禁止重新呼叫 Service 或 Repository。
| 項目 | readmodel-then | aggregate-then | success-failure |
|---|---|---|---|
| 資料來源 | $this->queryResult | Repository(DB) | $this->lastError |
| 前置條件 | 必須是 Query | 可為 Command / fixture | 任何操作後 |
| 是否查 DB | 否 | 是 | 否 |
| 驗證對象 | Query 回傳物件/陣列的內容 | Aggregate 屬性 | 操作成功/失敗 |
$this->queryResult 非 null:$this->assertNotNull($this->queryResult);assertCount,再逐筆驗證。$this->services->xxx 或 $this->repos->xxx。Then 查詢結果應包含進度 80,狀態為 "進行中"
$this->assertNotNull($this->queryResult);
$this->assertSame(80, $this->queryResult->getProgress());
$this->assertSame('IN_PROGRESS', $this->queryResult->getStatus());
Then 查詢結果應包含 2 個商品
$this->assertIsArray($this->queryResult);
$this->assertCount(2, $this->queryResult);
And 第一個商品的 ID 應為 "PROD-001",數量為 2
And 第二個商品的 ID 應為 "PROD-002",數量為 1
$this->assertSame('PROD-001', $this->queryResult[0]->getProductId());
$this->assertSame(2, $this->queryResult[0]->getQuantity());
$this->assertSame('PROD-002', $this->queryResult[1]->getProductId());
$this->assertSame(1, $this->queryResult[1]->getQuantity());
Then 查詢結果應包含以下課程:
| 課程 ID | 標題 | 進度 |
| 1 | React 入門 | 80 |
| 2 | Vue 進階 | 0 |
$expected = [
['課程 ID' => 1, '標題' => 'React 入門', '進度' => 80],
['課程 ID' => 2, '標題' => 'Vue 進階', '進度' => 0],
];
$this->assertIsArray($this->queryResult);
$this->assertCount(count($expected), $this->queryResult);
foreach ($expected as $i => $row) {
$item = $this->queryResult[$i];
$this->assertSame((int) $row['課程 ID'], $item->getCourseId());
$this->assertSame($row['標題'], $item->getTitle());
$this->assertSame((int) $row['進度'], $item->getProgress());
}
Then 查詢結果應為空
$this->assertTrue(
$this->queryResult === null
|| (is_array($this->queryResult) && count($this->queryResult) === 0),
'預期查詢結果為空,但實際有資料'
);
Then 查詢結果的總數應為 25
And 當前頁資料應為 10 筆
$this->assertNotNull($this->queryResult);
$this->assertSame(25, $this->queryResult->getTotal());
$this->assertCount(10, $this->queryResult->getItems());
Then 查詢結果應包含商品 "PROD-001"
$this->assertIsArray($this->queryResult);
$productIds = array_map(fn ($item) => $item->getProductId(), $this->queryResult);
$this->assertContains('PROD-001', $productIds);
| 中文 | Enum 值 |
|---|---|
| 進行中 | IN_PROGRESS |
| 已完成 | COMPLETED |
| 未開始 | NOT_STARTED |
| 已付款 | PAID |
| 待付款 | PENDING |
| 已取消 | CANCELLED |
$this->services->xxx、$this->repos->xxx;只讀 $this->queryResult。getXxx()),禁止以陣列 key 讀取物件屬性。assertCount)與「內容」(逐項 getter 斷言)。$this->queryResult(包含重指派、排序)。assertIsArray 再 assertCount,避免 null 造成誤導錯誤。$this->queryResultassertCount + 內容逐項驗證assertNotNull$this->queryResult