test-doubles-mocking — Claude Code skill: PHPUnit mocks for Symfony
test-doubles-mocking — a skill for creating test doubles with PHPUnit mocks in Symfony, used to replace slow or external dependencies, verify method calls, and write simplified repository fakes in isolated unit tests.
MIT ★ 234 updated 2026-10-05
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a claude-codeWhat test-doubles-mocking does
The skill outlines a workflow to choose the right double type: use a stub to return values, a mock to verify interactions, or a fake to provide a working simplified implementation. Create a double via $this->createMock(Interface::class), configure behaviour with willReturn(), willThrowException(), or willReturnCallback(), then verify calls only when the interaction matters to the test.
Key guardrails: do not mock the class under test, mock interfaces rather than concrete classes, and avoid over-mocking — logic touching the database belongs in a functional test with a real repository. For complex cases, write a fake implementation of the interface under tests/Fake.
What it helps with
- isolate a unit test from slow or non-deterministic external dependencies
- verify that a class calls a collaborator method with the correct arguments
- replace a repository with a lightweight in-memory fake
- decide between stub, mock, spy or fake based on what the test needs
Example prompts for the agent
- Create a mock for a payment gateway and assert the service passes the correct amount to charge()
- Write an in-memory fake repository that implements the Repository interface for fast business logic tests
- Use willReturnOnConsecutiveCalls() to make the double return different values on repeated calls
How to install test-doubles-mocking
1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a claude-code2Manually: put the files in place
~/.claude/skills/test-doubles-mocking/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/test-doubles-mocking/
1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a codex2Manually: put the files in place
.agents/skills/test-doubles-mocking/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a cursor2Manually: put the files in place
.cursor/skills/test-doubles-mocking/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install dev-toolings/superpowers-symfony content/skills/test-doubles-mocking2Manually: put the files in place
.github/skills/test-doubles-mocking/SKILL.md1Skills CLI (Vercel)
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a gemini-cli2Platform CLI
gemini skills install https://github.com/dev-toolings/superpowers-symfony --path content/skills/test-doubles-mockingManually: put the files in place
.devin/skills/test-doubles-mocking/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about test-doubles-mocking
How do I install test-doubles-mocking in Claude Code?
Run npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a claude-code, then open ~/.claude/skills/test-doubles-mocking/SKILL.md.
What does the test-doubles-mocking skill do?
It provides a workflow for creating PHPUnit test doubles—stub, mock, spy, fake—to replace slow dependencies and verify method calls in isolated unit tests.
When should I mock versus write a fake?
Mock when you need to verify an interaction or stabilize an external dependency. Write a fake when the double needs real logic but simplified, such as an in-memory store instead of a database.
Source text
SKILL.md · MIT
---
name: test-doubles-mocking
description: Create test doubles with PHPUnit mocks for isolated unit testing in Symfony
capabilities: [read, search]
tags: [testing]
# projected by `bun run build` — do not edit by hand
allowed-tools:
- Read
- Glob
- Grep
---
# Test Doubles Mocking (Symfony)
## Use when
- A class under test depends on a collaborator that is slow, external or non-deterministic, such as a payment gateway or a message bus.
- An interaction must be verified, such as `persist()` and `flush()` or a dispatched message.
- A repository needs an in-memory fake implementing its interface.
- Choosing between a dummy, stub, mock, spy or fake.
## Default workflow
1. Pick the double by need: stub to feed values, mock to verify a call, fake for a working simplified implementation.
2. Create it with `$this->createMock(Interface::class)` and stub with `->method('charge')->willReturn(...)`.
3. Verify only when the interaction matters: `expects($this->once())->with(...)`, or `$this->callback()` to inspect a dispatched message.
4. Script behavior with `willReturnOnConsecutiveCalls()`, `willThrowException()` or `willReturnCallback()`.
5. For repositories, write an `InMemory` fake implementing the interface.
6. Use `ProphecyTrait` with `prophesize()` and `reveal()` only if the project already relies on Prophecy.
## Guardrails
- Do not mock the class under test; a partial mock (`onlyMethods()`) is a last resort.
- Mock interfaces, not concrete classes.
- Prefer stubs over mocks, with one mock assertion per test.
- Do not over-mock: behavior that touches the database belongs in a functional test with the real repository.
## Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.
## Output contract
- The double type chosen for each collaborator, and why.
- Interactions verified, limited to those that matter.
- Fakes added under `tests/Fake`, if any.
## References
- `reference.md`
© dev-toolings · MIT · dev-toolings/superpowers-symfony