Files
agent-unit-testing/.claude/skills/laravel-mock-helper/skill.md
T
Pham-Tan-Thien 2045c856e9 feat: complete Smartgift AI Laravel unit testing toolkit
- Add 10 core testing guides (setup, AAA principles, PHPUnit/Pest, mocking, anti-patterns, PHP 8.4+, debugging, data factories, advanced edge cases)
- Add 13 component testing guides covering all Laravel layers
- Add standard templates for PHPUnit 10/11 and Pest v2/v3 including ArchitectureTest
- Add Docker smart test runner, dependency installer, and CI/CD templates (GitHub Actions, GitLab CI)
- Add 4 Claude Code skills (laravel-test-setup, laravel-unit-test with --all mode, laravel-test-review, laravel-mock-helper)
- Add single unified installer script (sg-install-unit-testing.sh) with global support, CLI runners, and 1-click updater (sg-test-update)
- Add comprehensive documentation (README.md, USAGE-GUIDE.md)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-07 16:41:37 +07:00

1.8 KiB

name, description
name description
laravel-mock-helper Phân tích một Class hoặc Interface bất kỳ và tự động sinh khối mã thiết lập Mock (Mockery / Laravel Fakes) sẵn sàng đưa vào test.

Skill: Laravel Mock Helper

Skill này hỗ trợ lập trình viên sinh nhanh mã giả lập (Mocking code) cho một Interface, Repository hoặc Service phức tạp.

Cách kích hoạt

/laravel-mock-helper <tên_class_hoặc_interface_hoặc_đường_dẫn>

Ví dụ: /laravel-mock-helper App\Contracts\PaymentGatewayInterface


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, bao gồm kiểu dữ liệu của tham số và kiểu trả về.
  3. Sinh ra 2 phiên bản mã Mockery:
    • Phiên bản Happy Path (Thành công): Mock trả về dữ liệu mẫu chuẩn theo kiểu trả về.
    • Phiên bản Exception / Failure: Mock ném ra ngoại lệ hoặc trả về false/null.
  4. Sinh kèm cú pháp kiểm tra số lần gọi (->once(), ->withArgs(...)).

Mẫu kết quả trả về:

// ==========================================
// THIẾT LẬP MOCK: PaymentGatewayInterface
// ==========================================

// 1. Khởi tạo mock
$gatewayMock = Mockery::mock(\App\Contracts\PaymentGatewayInterface::class);

// Kịch bản A: Happy Path
$gatewayMock->shouldReceive('charge')
    ->once()
    ->with(Mockery::type('float'), Mockery::type('string'))
    ->andReturn(new \App\DTOs\TransactionResult(success: true, id: 'TXN_123'));

// Kịch bản B: Exception Failure
$gatewayMock->shouldReceive('charge')
    ->once()
    ->andThrow(new \App\Exceptions\PaymentGatewayException('Connection timed out'));