home / skills / hoangnguyen0403 / agent-skills-standard / testing
This skill enforces PHP testing standards using Pest or PHPUnit, emphasizing TDD, isolation, and data-driven tests for unit and integration layers.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill testingReview the files below or copy the command above to add this skill to your agents.
---
name: PHP Testing
description: Unit and integration testing standards for PHP applications.
metadata:
labels: [php, testing, phpunit, pest, tdd]
triggers:
files: ['tests/**/*.php', 'phpunit.xml']
keywords: [phpunit, pest, mock, assert, tdd]
---
# PHP Testing
## **Priority: P1 (HIGH)**
## Structure
```text
tests/
├── Unit/
├── Integration/
└── Feature/
```
## Implementation Guidelines
- **Pest/PHPUnit**: Use Pest for DX or PHPUnit for legacy parity.
- **TDD Flow**: Follow Red-Green-Refactor cycle for new logic.
- **Isolation**: Mock dependencies via **Mockery** or PHPUnit mocks.
- **Strict Assertions**: Favor `assertSame` over `assertTrue`.
- **Data Providers**: Run tests against multiple sets via `@dataProvider`.
- **Categorize**: Separate Unit (isolated) from Integration (DB/API).
## Anti-Patterns
- **Testing Private**: **No Private Testing**: Validate public behavior only.
- **Over-Mocking**: **No Brittle Mocks**: Mock system boundaries only.
- **Blocking Tests**: **No Networking**: Use in-memory DBs and mocks.
- **Metric Chasing**: **No 100% Mania**: Prioritize quality over coverage.
## References
- [Testing Patterns & Mocks](references/implementation.md)
This skill codifies unit and integration testing standards for PHP applications to ensure reliable, maintainable test suites. It focuses on test structure, recommended tools (Pest or PHPUnit), isolation strategies, and practical anti-patterns to avoid. The guidance helps teams adopt a consistent TDD workflow and clear separation between Unit, Integration, and Feature tests.
The skill inspects test layout and tooling choices and enforces conventions like tests/Unit, tests/Integration, and tests/Feature. It recommends using Pest for developer experience or PHPUnit for legacy parity, applying Red-Green-Refactor TDD, and mocking external dependencies with Mockery or PHPUnit mocks. It also promotes strict assertions, data providers for varied inputs, and rules to prevent brittle or slow tests.
Should I test private methods directly?
No. Test public behavior and outcomes; private methods are implementation details and should be covered by public-facing tests.
When should I use Pest vs PHPUnit?
Choose Pest for developer ergonomics and cleaner syntax; use PHPUnit when you need compatibility with existing legacy suites or tooling that depends on it.