Php Testing
Testing & Qualityphp-testingPhp Testing is an Agent Skill for testing & quality published in the majiayu000/claude-skill-registry repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
PHP testing patterns: PHPUnit, test doubles, database testing.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/majiayu000/claude-skill-registry/blob/HEAD/skills/data/php-testing-notque-vexjoy-agent/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/php-testing, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
PHP Testing Skill
Overview
Apply PHPUnit testing patterns for PHP projects: unit tests with data providers, test doubles (stubs, mocks, Prophecy), database testing (Laravel/Symfony), HTTP testing, and coverage configuration.
See
references/patterns.mdfor full code examples, the failure modes table, and the commands reference.
Reference Loading Table
| Signal | Load These Files | Why |
|---|---|---|
| writing PHPUnit tests: data providers, mocks/stubs, database or HTTP tests, coverage config | patterns.md | Loads detailed guidance from patterns.md. |
Instructions
Phase 1: IDENTIFY
Determine what needs testing:
- Unit logic: use PHPUnit
TestCasewithtestprefix or@testannotation - Table-driven cases: use
@dataProviderstatic methods - Collaborator behavior: use stubs (return values only) or mocks (assert interactions)
- Database state: use
DatabaseTransactions(Laravel) orKernelTestCase(Symfony) - HTTP endpoints: use Laravel HTTP helpers or Symfony
WebTestCase
Phase 2: WRITE
Write tests following these rules:
- Call
parent::setUp()first in everysetUp()method - Use
assertSame()instead ofassertTrue($a === $b)for meaningful failure messages - Mock only collaborators and dependencies, never the class under test
- Keep tests independent -- do not use
@dependschains - Extract repetitive cases to
@dataProviderrather than duplicating test methods
For test doubles: use createStub() when you only need return values, createMock() when asserting method calls, and Prophecy (phpspec/prophecy-phpunit) for more expressive interaction assertions.
For database tests: use DatabaseTransactions (Laravel) or DoctrineTestBundle (Symfony) to roll back state after each test.
Phase 3: VERIFY
Run the test suite and confirm all tests pass:
./vendor/bin/phpunit
For coverage enforcement:
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text --coverage-min=80
GATE: All tests pass. Coverage threshold met if configured. No failure modes from references/patterns.md introduced.