AGENT SKILL
php-testing
Unit and integration testing standards for PHP applications. Use when writing PHPUnit unit tests or integration tests for PHP applications. (triggers: tests/**/*.php, phpunit.xml, phpunit, pest, mock, assert, tdd)
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
01 前言 Front Matter
- name
- php-testing
- description
- Unit and integration testing standards for PHP applications. Use when writing PHPUnit unit tests or integration tests for PHP applications. (triggers: tests/**/*.php, phpunit.xml, phpunit, pest, mock, assert, tdd)
02 资源文件 4
- 参考文档references/COPILOT-STUDIO-RATES.md5.7 KB
- 参考文档references/COST-ESTIMATOR.md3.5 KB
- 参考文档references/REGIONS.md2.7 KB
- 参考文档references/SERVICE-NAMES.md3.7 KB
03 SKILL.md 正文
PHP Testing
Priority: P1 (HIGH)
Structure
tests/
├── Unit/
├── Integration/
└── Feature/
Implementation Guidelines
- Standards: Use
PHPUnit(9/10+) orPest. Organize intoUnit/,Integration/, andFeature/. Class names should extendTestCase(e.g.,class OrderServiceTest extends TestCase). - TDD Workflow: Follow Red-Green-Refactor. Red: write failing test first for
createOrder(), then Green: implement minimal logic to pass, then Refactor. - Mocking: Use
createMock(PaymentService::class)for dependencies. Define behavior withexpects($this->once())andmethod('charge')withwith(100)->willReturn(true). DO NOT mock simple Data Objects. - Fluent Assertions:
assertSame checks type + value(===) — useassertSame('Test', $result->title)overassertEqualsto avoid type coercion surprises. Also useassertCount()andassertMatchesRegularExpression(). - Data Providers: Use
#[DataProvider('statusProvider')](PHPUnit 10+) with apublic static function statusProvider(): arrayordataset(Pest). - Isolation: Ensure tests are Independent and Repeatable. DB tests must use
TransactionsorSQLite :memory:. - Pest syntax: Use
it('creates an order', function() { ... })andexpect($result->title)->toBe('Test')for cleaner, more readable tests. - Coverage: Aim for
80%+line coverage. Usephpunit.xmlto whitelist specific directories. - Automation: Run tests on every PR using GitHub Actions or GitLab CI.
Anti-Patterns
- No testing private methods: Test through public interfaces only.
- No over-mocking internals: Mock only external boundaries.
- No real network/DB in unit tests: Use in-memory databases or mocks.
- No coverage-metric chasing: Prioritize meaningful assertions.