Skip to content
Back to skills

Symfony Testing

ASecurity

Test patterns for a Symfony backend: choosing the layer, KernelTestCase and WebTestCase, body tests validated against the OpenAPI contract, Doctrine fixtures, tagging tests with acceptance-criteria IDs, and keeping runs fast. Load when writing or fixing backend tests.

  • 13 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 6, 2026
developmentphpkotlinsqlexpresstestingdebuggingapidatabasebackend

Works with

  • cli
  • api

Security analysis

A100/100

Scanned November 6, 2026

npx -y skills add MiladNalbandi/keel-v2 --skill symfony-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Symfony Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Symfony Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/miladnalbandi-symfony-testing/badge)](https://www.skillsdirectory.com/skills/miladnalbandi-symfony-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: symfony-testing
description: "Test patterns for a Symfony backend: choosing the layer, KernelTestCase and WebTestCase, body tests validated against the OpenAPI contract, Doctrine fixtures, tagging tests with acceptance-criteria IDs, and keeping runs fast. Load when writing or fixing backend tests."
user-invocable: false
---

# Symfony test patterns

## Pick the lowest layer that can express the AC

| Layer | Use | Base class |
|---|---|---|
| Unit | Pure PHP, no framework | `PHPUnit\Framework\TestCase` |
| Kernel | Service wiring, no HTTP | `KernelTestCase` |
| Web | Status codes, validation, auth rules | `WebTestCase` |
| Body / contract | Request and response bodies conform to the contract | `WebTestCase` + a contract-validating assertion |
| Integration | Cross-layer flows, a real (test) database | `KernelTestCase` + `DoctrineTestBundle` transaction rollback |

## Tag every test with its AC

```php
#[Group('AC-003')]
public function testRejectsABookmarkWithoutAUrl(): void { /* ... */ }
```

keel runs one criterion's test by that group, and traces the test back by the ID in the
method name or a leading comment — same convention as every other stack, just PHPUnit's own
attribute for it.

## Body test shape

```php
#[Group('AC-002')]
final class BookmarkControllerTest extends WebTestCase
{
    #[Group('AC-002')]
    public function testCreatedBookmarkBodyMatchesTheContract(): void
    {
        $client = static::createClient();
        $client->request('POST', '/bookmarks', server: ['CONTENT_TYPE' => 'application/json'],
            content: json_encode(['url' => 'https://x.dev']));

        self::assertResponseStatusCodeSame(201);
        $body = json_decode($client->getResponse()->getContent(), true);
        self::assertArrayHasKey('id', $body);
        self::assertSame('https://x.dev', $body['url']);
        // validate $body against contracts/openapi.yaml the same way every other stack does —
        // a schema-validating assertion here, not a hand-picked subset of fields.
    }
}
```

## Fixtures and the database

- Reset state between tests with `DoctrineTestBundle`'s transaction rollback (`ResetDatabase` +
  `Factories` traits), not a full schema drop — slow, and unnecessary per test.
- Load fixtures through Doctrine fixture classes, not raw SQL scattered across tests; one
  fixture set per test class keeps a failing test's setup readable in the failure output.
- A migration is real production code — see `architecture`'s migration guidance, which
  applies here exactly as it does to any other stack's schema change.

## Keep runs fast

- Prefer `KernelTestCase` over `WebTestCase` when the AC doesn't need HTTP semantics — booting
  the kernel without the full request/response cycle is cheaper.
- Share one kernel across a test class rather than rebooting it per test method.
- `--filter` (used by `api_test_ac`) runs one AC's tests without paying for the whole suite.

## Rules keel enforces

- In RED only test files may change; in GREEN only production code — identical to every other
  stack, enforced by the same guard matrix, not by anything PHP-specific.
- A failure from a missing autoloader entry, an unconfigured service or a database connection
  problem is not a red test; fix the setup first, the same rule `debugging` states for every
  stack.
- Never mark a test `skipped` or `incomplete` to make a suite pass — a parked test is a weakened
  test, the same as `@Disabled` on the Kotlin side, and review blocks it.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.