Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add dev-toolings/superpowers-symfony --skill test-doubles-mocking -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/test-doubles-mocking/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/test-doubles-mocking/

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

Similar skills

All skills for Testing and QA →

From the same set51

The whole set →
tdd-with-phpunit The tdd-with-phpunit skill guides PHPUnit-driven work on Symfony features, from checking a failing test to refactoring after it passes. Use it for command, form, and external-service tests. CX Codex +1 ★ 234repo stars using-symfony-superpowers using-symfony-superpowers is a Claude Code skill that detects the Symfony version, selects a skill, and sequences steps for complex tasks. CX Codex +1 ★ 234repo stars interfaces-and-autowiring interfaces-and-autowiring guides Symfony dependency injection in Claude Code by binding interfaces, configuring #[Target] aliases, and decorating services cleanly. CX Codex +1 ★ 234repo stars symfony-cache Configure Symfony Cache pools, entry expiry, and tag-based invalidation with this skill. It helps when caching costly reads or preventing a burst of recomputations after a key expires. CX Codex +1 ★ 234repo stars rate-limiting rate-limiting guides Claude Code through setting up Symfony RateLimiter policies, controller attributes, and 429 responses with Retry-After headers. CX Codex +1 ★ 234repo stars api-platform-tests The api-platform-tests skill guides functional tests for Symfony API Platform resources, including response checks, filters, JSON schemas, and access control. Use it while building or changing API endpoints. CX Codex +1 ★ 234repo stars api-platform-serialization Skill configures API Platform serialization: field groups per operation, IRIs instead of nested objects, computed properties, and normalizer options. CX Codex +1 ★ 234repo stars symfony-scheduler Configures recurring tasks with the Symfony Scheduler component without system crontab entries. Useful for scheduled report generation, database cleanups, and Messenger syncs. CX Codex +1 ★ 234repo stars

Project sponsors

Companies that keep this analytics open