tyloo / atc
Fluent API testing for Symfony with JSON Schema validation, container mocking, and in-memory infrastructure swaps.
Requires
- php: >=8.4
- opis/json-schema: ^2.6
- softcreatr/jsonpath: ^0.10 || ^1.0
- symfony/browser-kit: ^7.0 || ^8.0
- symfony/dependency-injection: ^7.0 || ^8.0
- symfony/framework-bundle: ^7.0 || ^8.0
- symfony/http-foundation: ^7.0 || ^8.0
- webmozart/assert: ^2.3
Requires (Dev)
- doctrine/doctrine-bundle: ^2.18 || ^3.2
- doctrine/orm: ^3.6
- phpunit/phpunit: ^13.0
- symfony/cache: ^7.0 || ^8.0
- symfony/clock: ^7.0 || ^8.0
- symfony/http-client: ^7.0 || ^8.0
- symfony/mailer: ^7.0 || ^8.0
- symfony/messenger: ^7.0 || ^8.0
- symfony/notifier: ^7.0 || ^8.0
- symfony/yaml: ^7.0 || ^8.0
- zenstruck/foundry: ^2.9
Suggests
- doctrine/orm: Required for InteractsWithDatabase
- symfony/cache: Required for InteractsWithCache
- symfony/clock: Required for InteractsWithClock
- symfony/http-client: Required for InteractsWithHttpClient
- symfony/mailer: Required for InteractsWithMailer
- symfony/messenger: Required for InteractsWithMessenger
- symfony/notifier: Required for InteractsWithNotifier
- zenstruck/foundry: Recommended for test data factories
README
atc — APITestCase
Fluent API testing for Symfony with JSON Schema validation, container mocking, and in-memory infrastructure swaps.
Why atc?
Symfony's WebTestCase gives you the kernel and a browser. Everything else — fluent assertions, JSON Schema validation, container mocking, in-memory transports — you build yourself, every project. atc is the layer that closes that gap, inspired by Laravel's testing helpers and api-platform/core's ApiTestCase but purpose-built for modern Symfony.
Highlights
- Fluent HTTP DSL —
$this->get('/users')->assertOk()->assertJsonContains([...]) - JSON Schema (Draft 2020-12), JSON subset, and JSONPath assertions
- Pluggable auth via the
AuthenticatorInterfaceplusactingAs($user)andwithToken() - Container-aware mocking —
mockService,partialMockService,setService,defaultMocks() - In-memory swaps by default for Messenger, Mailer, Notifier, HTTP client, Cache, and Clock
- Database, performance, and infrastructure assertions —
assertDatabaseHas,assertResponseTimeLessThan,assertEmailSent,assertMessageDispatched, …
Installation
composer require --dev tyloo/atc
Quick start
One test method. Auth, mocking, fluent assertions, JSON Schema validation, database checks — all without setup boilerplate.
public function test_creates_a_user_and_sends_welcome_email(): void { $admin = AdminFactory::createOne(); // create an admin via a Zenstruck Foundry factory $this->mockService(MailerInterface::class) // swap the real Mailer for a PHPUnit mock in the container ->expects(self::once()) // expect exactly one outbound call ->method('send'); // …specifically MailerInterface::send() $this->actingAs($admin) // authenticate every following request as $admin ->post('/api/users', json: [ // POST with a JSON body (Content-Type set automatically) 'email' => 'alice@example.com', 'name' => 'Alice', ]) ->assertCreated() // HTTP 201 Created ->assertMatchesJsonSchema('users/create.json') // validate the body against a JSON Schema (Draft 2020-12) ->assertJsonPath('$.data.email', 'alice@example.com') // pinpoint a single field via JSONPath ->assertHeader('Location', '/api/users/1'); // verify the Location header points at the new resource $this->assertDatabaseHas(User::class, ['email' => 'alice@example.com']); // confirm Doctrine actually persisted the row }
One method. Seven infrastructure concerns covered without a single line of setup boilerplate.
Trait reference
| Trait | Purpose |
|---|---|
InteractsWithApi |
HTTP requests + fluent response assertions (in base class) |
InteractsWithContainer |
Container service mocking (in base class) |
InteractsWithAuth |
actingAs, authenticators (in base class) |
InteractsWithDatabase |
assertDatabaseHas, etc. |
InteractsWithMessenger |
In-memory transport + assertMessageDispatched |
InteractsWithMailer |
Email assertions |
InteractsWithNotifier |
Notification assertions |
InteractsWithHttpClient |
MockHttpClient + assertions |
InteractsWithCache |
ArrayAdapter + assertions |
InteractsWithClock |
MockClock with travel/freeze |
Documentation
See docs/:
Recommended companions
- Zenstruck Foundry — test data factories.
- DAMA/DoctrineTestBundle — alternative DB lifecycle.
Contributing
See CONTRIBUTING.md and our Code of Conduct.
Security
Report vulnerabilities via GitHub Security Advisories. See SECURITY.md.
License
MIT © Julien Bonvarlet
