Agent-skills-standard php-testing
Write unit and integration tests for PHP applications with PHPUnit and Pest. Use when writing PHPUnit unit tests or integration tests for PHP applications. (triggers: tests/**/*.php, phpunit.xml, phpunit, pest, mock, assert, tdd)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/php/php-testing" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-php-testing && rm -rf "$T"
manifest:
skills/php/php-testing/SKILL.mdsource content
PHP Testing
Priority: P1 (HIGH)
Structure
See implementation examples for test directory layout.
Write Tests with PHPUnit and Pest
- Standards: Use
(9/10+) orPHPUnit
. Organize intoPest
,Unit/
, andIntegration/
. Class names should extendFeature/
.TestCase - TDD Workflow: Follow Red-Green-Refactor. Write failing test first, implement minimal logic, then refactor.
See implementation examples for PHPUnit service test with mock.
Apply Assertions and Data Providers
- Fluent Assertions: Use
(assertSame
) over===
to avoid type coercion. Also useassertEquals
andassertCount()
.assertMatchesRegularExpression() - Data Providers: Use
(PHPUnit 10+) or#[DataProvider('statusProvider')]
(Pest).dataset
See implementation examples for Pest expressive syntax with datasets.
Isolate Test Dependencies
- Mocking: Use
for dependencies. NOT mock simple Data Objects.createMock() - Isolation: Ensure tests Independent and Repeatable. DB tests must use
orTransactions
.SQLite :memory: - Coverage: Aim for
line coverage. Use80%+
to whitelist specific directories.phpunit.xml - 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.