api-platform-tests
Installation
SKILL.md
Api Platform Tests (Symfony)
Use when
- Writing functional tests for API Platform endpoints: collection, item, create, update, delete.
- Asserting validation errors (422) and access control (401, 403).
- Checking filters, pagination, or the JSON schema of responses.
- Setting up a clean database and test data for API tests.
Default workflow
- Extend
ApiTestCaseand seed data with Foundry factories (createOne,createMany). - Reset state with
#[ResetDatabase]and theFactoriestrait, with DAMA rolling back each test. - Call
static::createClient()->request()and assert the status code, content type, andassertJsonContains(). - Authenticate with
auth_bearerand cover the anonymous, owner, and other-user cases. - Assert
memberandtotalItemsfor filters and pagination (hydra:-prefixed only withhydra_prefix: true). - Assert the shape with
assertMatchesResourceItemJsonSchema()andassertMatchesResourceCollectionJsonSchema().