tdd-with-phpunit

Installation
SKILL.md

Tdd With Phpunit (Symfony)

Use when

  • Driving a feature with RED-GREEN-REFACTOR using PHPUnit 10/11 class-based tests.
  • Choosing between TestCase, KernelTestCase and WebTestCase for a new behavior.
  • Testing a console command, or an invalid form that must answer 422.
  • Swapping an external service for a double through the test container.

Default workflow

  1. RED: pick the base class, write the test with #[Test], #[DataProvider] and #[CoversClass], run it and check it fails for the right reason.
  2. GREEN: write the minimum code that passes.
  3. REFACTOR with the suite green, re-running it after each change.
  4. Replace an external boundary with static::getContainer()->set(Service::class, $mock).
  5. Test commands with CommandTester, or with runCommand() and assertCommandIsSuccessful() on Symfony 8.1+.
  6. Assert invalid form submissions with assertResponseIsUnprocessable().
Installs
75
GitHub Stars
224
First Seen
Sep 18, 2026