feat: add comprehensive unit testing support for CakePHP
- Add 4 CakePHP Claude Code skills: cakephp-unit-test, cakephp-test-setup, cakephp-test-review, cakephp-mock-helper - Add 11 CakePHP PHPUnit component templates (Table, Entity, Controller, Service, Command, Component, Middleware, Mailer, Form, Behavior, Helper) - Add CakePHP configs (phpunit.xml.dist, app_local.test.php for SQLite in-memory) - Add comprehensive CakePHP documentation and component guides - Update test-runner.sh and installer to auto-detect Laravel and CakePHP - Add CakePHP CI/CD templates for GitHub Actions and GitLab CI - Update system prompt, verification checklist, and README with dedicated guides
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
---
|
||||
name: cakephp-mock-helper
|
||||
description: Phân tích một Class, Interface hoặc Table CakePHP và tự động sinh khối mã thiết lập Mock (PHPUnit Mock Double / Mockery) chuẩn cú pháp.
|
||||
---
|
||||
|
||||
# Skill: CakePHP Mock Helper
|
||||
|
||||
Skill này hỗ trợ lập trình viên sinh nhanh mã giả lập (Mocking code) cho một CakePHP Component, Table, Service hoặc External Client.
|
||||
|
||||
## Cách kích hoạt
|
||||
```text
|
||||
/cakephp-mock-helper <tên_class_hoặc_đường_dẫn>
|
||||
```
|
||||
*Ví dụ*: `/cakephp-mock-helper App\Service\PaymentGatewayService`
|
||||
*Ví dụ*: `/cakephp-mock-helper App\Controller\Component\StripeComponent`
|
||||
|
||||
---
|
||||
|
||||
## Quy trình xử lý của Agent:
|
||||
1. Đọc nội dung file class/interface được cung cấp.
|
||||
2. Liệt kê toàn bộ các `public methods`, tham số và kiểu trả về.
|
||||
3. Sinh ra 2 phiên bản mã Mock:
|
||||
- **Phiên bản PHPUnit Native Mock** (`$this->createMock(...)` hoặc `$this->getMockBuilder(...)`).
|
||||
- **Phiên bản Mockery** (`Mockery::mock(...)`).
|
||||
4. Kèm theo cả Happy Path (trả về kết quả hợp lệ) và Failure/Exception case.
|
||||
|
||||
## Mẫu kết quả trả về:
|
||||
|
||||
```php
|
||||
// ==========================================
|
||||
// 1. DÙNG PHPUNIT NATIVE MOCK (Khuyên dùng cho CakePHP)
|
||||
// ==========================================
|
||||
$serviceMock = $this->createMock(\App\Service\PaymentGatewayService::class);
|
||||
|
||||
// Kịch bản Happy Path:
|
||||
$serviceMock->expects($this->once())
|
||||
->method('charge')
|
||||
->with(150.00, 'USD')
|
||||
->willReturn(['status' => 'success', 'transaction_id' => 'TXN_999']);
|
||||
|
||||
// Kịch bản Exception:
|
||||
$serviceMock->expects($this->once())
|
||||
->method('charge')
|
||||
->willThrowException(new \RuntimeException('Payment gateway timeout'));
|
||||
|
||||
// ==========================================
|
||||
// 2. DÙNG MOCKERY (Nếu dự án có cài Mockery)
|
||||
// ==========================================
|
||||
$serviceMock = Mockery::mock(\App\Service\PaymentGatewayService::class);
|
||||
$serviceMock->shouldReceive('charge')
|
||||
->once()
|
||||
->with(150.00, 'USD')
|
||||
->andReturn(['status' => 'success', 'transaction_id' => 'TXN_999']);
|
||||
```
|
||||
Reference in New Issue
Block a user