From zenbu-powers
處理 Then 步驟中驗證 Aggregate 屬性狀態(透過 Repository 查 DB)的 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 適用於 **Then** 步驟中驗證 **DB 端 Aggregate 屬性狀態** 的語句:
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 步驟中驗證 DB 端 Aggregate 屬性狀態 的語句:
關鍵字:應為、的...為、數量應為、應包含、應不包含
透過 $this->repos->xxx->findXxx() 從 WordPress DB 取回當前 Aggregate 狀態,然後使用 PHPUnit 斷言驗證屬性值。不重查 Service,不存取 $this->queryResult(那屬於 readmodel-then)。
| 項目 | aggregate-then | readmodel-then | success-failure |
|---|---|---|---|
| 資料來源 | Repository(DB) | $this->queryResult | $this->lastError |
| 驗證對象 | Aggregate 屬性 | Query 回傳結果內容 | 操作成功/失敗 |
| 前置步驟 | 通常是 Command | 必須是 Query | 通常是 Command/Query |
| 是否查 DB | 是(Repository) | 否 | 否 |
$this->ids 取得主體 ID:$userId = $this->ids['Alice'];$progress = $this->repos->lessonProgress->findByUserAndLesson($userId, 1);assertSame(嚴格型別比對)為主,字串用 assertSame、集合用 assertCount。Then 用戶 "Alice" 在課程 1 的進度應為 80%,狀態應為 "進行中"
$userId = $this->ids['Alice'];
$progress = $this->repos->lessonProgress->findByUserAndLesson($userId, 1);
$this->assertNotNull($progress, '找不到課程進度');
$this->assertSame(80, $progress->getProgress());
$this->assertSame('IN_PROGRESS', $progress->getStatus());
Then 訂單 "ORD-001" 的總金額應為 90000,狀態應為 "已付款"
$orderId = $this->ids['ORD-001'];
$order = $this->repos->order->findById($orderId);
$this->assertNotNull($order, '找不到訂單');
$this->assertSame(90000, $order->getTotalAmount());
$this->assertSame('PAID', $order->getStatus());
Then 用戶 "Alice" 的購物車應包含以下商品:
| 商品 ID | 數量 |
| PROD-001 | 2 |
| PROD-002 | 1 |
$userId = $this->ids['Alice'];
$expected = [
['商品 ID' => 'PROD-001', '數量' => 2],
['商品 ID' => 'PROD-002', '數量' => 1],
];
foreach ($expected as $row) {
$item = $this->repos->cartItem->findByUserAndProduct($userId, $row['商品 ID']);
$this->assertNotNull($item, "找不到商品 {$row['商品 ID']}");
$this->assertSame((int) $row['數量'], $item->getQuantity());
}
Then 用戶 "Alice" 的購物車應不包含商品 "PROD-001"
$userId = $this->ids['Alice'];
$item = $this->repos->cartItem->findByUserAndProduct($userId, 'PROD-001');
$this->assertNull($item);
Then 用戶 "Alice" 的購物車應有 3 個商品
$userId = $this->ids['Alice'];
$items = $this->repos->cartItem->findByUser($userId);
$this->assertCount(3, $items);
| 中文 | Enum 值 | 適用實體 |
|---|---|---|
| 進行中 | IN_PROGRESS | Progress, Status |
| 已完成 | COMPLETED | Progress, Status |
| 未開始 | NOT_STARTED | Progress, Status |
| 已付款 | PAID | Order |
| 待付款 | PENDING | Order |
| 已取消 | CANCELLED | Order |
$this->repos->xxx,禁止直連 $wpdb、禁用 Service、禁讀 $this->queryResult。save()、無 delete()、無 update())。assertSame;數值比大小用 assertGreaterThan 等;字串包含用 assertStringContainsString。$this->repos->xxx 進行assertNotNull / assertNull$wpdb、Service 呼叫、寫入操作$this->queryResult(那屬 readmodel-then)