ferroxlabs/wayland/php-testing-patterns
Claude Code and agent skill by ferroxlabs/wayland
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Guides expert-level php testing patterns implementation: php and testing decision frameworks, production-ready patterns, and concrete templates for php testing patterns workflows. Use when the user asks about php testing patterns, php testing patterns configuration, or php best practices for php projects. Do NOT use when the user needs a different languages runtimes capability -- check sibling skills in the languages runtimes subcategory.
Install
npx vskill@latest install ferroxlabs/wayland/php-testing-patternsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as ferroxlabs/wayland/php-testing-patterns.
PHP Testing Patterns
When to Use
Use this skill when:
- User asks how to structure PHPUnit test classes, test suites, or test configuration for a PHP project
- User wants to implement TDD, BDD, or mutation testing workflows in a PHP codebase
- User needs guidance on mocking, stubbing, or faking dependencies in PHP using PHPUnit, Mockery, or Prophecy
- User asks about test doubles, data providers, test isolation, or avoiding shared state between tests
- User wants to add testing to an existing Laravel, Symfony, Slim, or plain PHP application
- User is asking about code coverage targets, mutation score thresholds, or CI integration for PHP tests
- User needs to test infrastructure concerns in PHP -- database repositories, HTTP clients, queue consumers, file system operations
- User asks about Pest PHP, Behat, Codeception, or how to choose between PHP testing frameworks
Do NOT use this skill when:
- User needs frontend JavaScript testing for a PHP application -- use a JavaScript testing skill
- User is asking about API contract testing with OpenAPI or Pact -- check the contract testing skill
- User needs load or performance testing tools like k6 or Gatling -- those are separate concerns
- User is asking about PHP static analysis with PHPStan or Psalm -- use the PHP static analysis skill
- User needs CI/CD pipeline configuration that goes beyond test execution -- check the CI/CD pipeline skill
- User is asking about general PHP architecture patterns without a testing angle -- check the PHP architecture skill
- User wants database schema migration tooling -- that is separate from testing the data layer
Process
1. Assess the PHP Project Context
Before recommending any testing pattern, gather the following specific information:
- Framework in use: Laravel, Symfony, Slim, WordPress, or framework-free. Each has idiomatic test helpers and base classes that change what you scaffold.
- PHP version: PHP 8.0+ enables named arguments, attributes, and match expressions that affect how test data providers are declared. PHP 7.4 projects cannot use these idioms.
- Existing test coverage: Run
./vendor/bin/phpunit --coverage-textto get the current line, method, and class coverage. If coverage is zero, start with integration tests for the most business-critical path before writing unit tests. - Dependency injection style: Constructor injection makes mocking trivial. Service locator or static facades (Laravel) require specific helpers like
app()->instance()orMockery::mock()bound to the container. - Test execution time: Run
./vendor/bin/phpunit --log-junit test-results.xmland inspect slow tests. If the suite takes more than 90 seconds locally, the team will skip it. Identify the slow subset and isolate it. - Database interaction: Determine whether the codebase uses an ORM (Eloquent, Doctrine), raw PDO, or a query builder. Each requires different database testing strategies -- in-memory SQLite, transactions with rollback, or a dedicated test database with fixtures.
2. Select the Testing Framework and Toolchain
PHP has a settled ecosystem. Make concrete choices, not generic ones:
- PHPUnit 10/11: The standard. Use it unless the team explicitly prefers Pest. PHPUnit 10 dropped legacy annotations in favor of PHP 8 attributes (
#[Test],#[DataProvider],#[Before]). All new projects should target PHPUnit 11. - Pest PHP 2/3: A wrapper over PHPUnit with a functional API. Use it when the team comes from a JavaScript/Ruby background, when tests read as specifications, or when the codebase is Laravel-first. Pest's
it()anddescribe()blocks map directly to Gherkin-style thinking without requiring Behat. - Mockery 1.6+: Prefer over PHPUnit's built-in mock objects for complex interaction expectations. PHPUnit mocks are verbose for chained methods and partial mocks. Mockery's
shouldReceive()->once()->with()->andReturn()chain is more readable. - Prophecy: Bundled with older PHPUnit versions. Avoid in new projects -- Mockery is more actively maintained and integrates better with Pest.
- Codeception: Use only when end-to-end acceptance tests against a real browser (via Selenium or Playwright PHP bindings) are required. It is overkill for unit and integration testing.
- Infection PHP (mutation testing): Install as a dev dependency. Target a mutation score indicator (MSI) above 70% for critical domain logic. Run it in CI on changed files only, not the entire suite.
- php-code-coverage with Xdebug or PCOV: PCOV is 3--5x faster than Xdebug for coverage collection and does not require the full debugger extension. Use PCOV in CI; use Xdebug locally only when debugging.
Install the recommended baseline:
3. Establish the Test Directory Structure
A well-organized test directory prevents the most common long-term maintenance problems:
Key rules for this structure:
Unit/tests have zero I/O. No database, no HTTP, no filesystem. They must run in under 5ms each.Integration/tests touch real infrastructure -- a test database, a real HTTP client pointed at a wiremock server, or a real filesystem in/tmp.Fixture/holds stateless factory objects and static stub files. Never embed fixture data inside test methods.Support/holds abstract base test cases with setup helpers, not generic traits that leak state.
Configure phpunit.xml to map test suites explicitly:
This allows ./vendor/bin/phpunit --testsuite Unit to run only fast tests in pre-commit hooks.
4. Implement Core Unit Testing Patterns
Unit tests in PHP follow these concrete patterns:
Arrange-Act-Assert (AAA) with strict naming:
Data providers for boundary testing:
Test doubles -- choosing the right one:
- Stub: Returns a fixed value. Use when the return value drives the unit under test's behavior but you do not care how many times it is called.
- Mock: Asserts interaction. Use when the purpose of the unit is to call a collaborator correctly -- for example, ensuring an event is dispatched.
- Spy: Records calls for later assertion. Use with Mockery's
shouldHaveReceived()for post-act verification, which reads more naturally. - Fake: A real, working implementation without side effects. Use for repositories -- an
InMemoryOrderRepositorythat stores in an array is faster and more realistic than a mock.
5. Implement Integration Testing Patterns
Integration tests require special infrastructure management:
Database integration tests -- transaction rollback strategy:
This pattern runs each test in an uncommitted transaction. It is 10--20x faster than truncating tables between tests and does not require a test-specific database schema reset.
HTTP integration tests -- use an in-process client: In Laravel, use $this->getJson('/api/orders') which invokes the kernel without a real HTTP socket. In Symfony, use $this->client->request('GET', '/api/orders') from WebTestCase. Never fire real HTTP requests from unit or integration tests -- use a real HTTP client only in acceptance tests.
Doctrine/ORM integration tests: Use an in-memory SQLite database for Doctrine integration tests when the schema does not use MySQL-specific features. Configure a separate test entity manager that uses doctrine/dbal SQLite:
For tests that require MySQL-specific behavior (JSON columns, full-text search), provision a real MySQL container in CI using Docker Compose and depends_on health checks.
Wiremock / HTTP stub servers: When testing code that calls external APIs, do not use Mockery to mock the HTTP client interface. Instead, use a real HTTP server stub. PHPUnit has no built-in server stub, but you can use the wiremock-php package or a simple PHP built-in server fixture. This catches serialization bugs, header handling, and timeout behavior that interface mocks cannot.
6. Apply Object Mother and Test Builder Patterns
Hardcoded test data scattered across test methods is the most common cause of brittle test suites. Use these two patterns:
Object Mother -- a factory class that returns pre-configured domain objects:
Test Builder -- a fluent builder for tests that need precise control:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 96 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingsrc/process/resources/skills-library/bodies/skills/software-engineering/php-testing-patterns/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ferroxlabs/wayland/php-testing-patterns)