Skip to content
Development
Skill

/test-doubles-mocking

Create test doubles with PHPUnit mocks for isolated unit testing in Symfony

From plugin
superpowers-symfony
23344 skills14 agents13 commands1 hook

Claude Code

$ npx -y skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking --agent claude-code

SKILL.md

test-doubles-mocking.SKILL.md
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`
Read more
@dev-toolings
Ships withsuperpowers-symfony

Superpowers Symfony gives coding agents deep, version-accurate Symfony expertise: from Doctrine schema design and API Platform REST/GraphQL APIs to test-driven development, async Messenger workflows, caching, rate limiting, and clean architecture.

23344 skills14 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
233
Star history of dev-toolings/superpowers-symfony on GitHub, a chart by star-history.com

Other skills on superpowers-symfony.

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills2w309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react5d252k
@facebook@facebookInstall Skill

Questions about test-doubles-mocking.

Which coding agents can use test-doubles-mocking?
test-doubles-mocking installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.