api-platform-tests
Skill2 starsChanged 6 months agoMITView on GitHub
Write production-grade API Platform 4.3 functional tests with `ApiTestCase` — Foundry factories + `ResetDatabase`, DAMA Doctrine test bundle (transaction-rollback per test), ParaTest for parallel execution, lightweight md5 password hashing in test env, reusable authenticated client (`createClientWithCredentials`), `disableReboot()` for multi-request flows, `findIriBy()`, schema assertions (`assertMatchesResourceItemJsonSchema`, `assertMatchesResourceCollectionJsonSchema`, `assertMatchesJsonSchema`), the 4.x JSON-LD shape (`member`, `totalItems`, `view`, `next` — no `hydra:` prefix), and the **exhaustive failure-mode catalog** every write operation must cover (422 invalid payload, 401 anonymous, 403 wrong role, 404 unknown id, 405 wrong verb, 409 unique-constraint clash, 415 wrong Content-Type, MaxDepth circular serialization, async retry / DLQ). Trigger when writing or reviewing API tests, hitting "expected hydra:member but found member", debugging slow suites, setting up CI test pipelines, adopting scenario-based test naming, or auditing negative-path coverage ("missing 422 test", "no 401 assertion", "failure modes").
In this repository52 other files it gives its agents.
- api-platform-dto-resourcesSkill
- api-platform-errorsSkill
- api-platform-file-uploadSkill
- api-platform-filtersSkill
- api-platform-identifiersSkill
- api-platform-mcpSkill
- api-platform-mutatorsSkill
- api-platform-openapiSkill
- api-platform-paginationSkill
- api-platform-performanceSkill
- api-platform-resilienceSkill
- api-platform-resourcesSkill
- api-platform-securitySkill
- api-platform-serializationSkill
- api-platform-state-processorsSkill
- api-platform-state-providersSkill
- api-platform-upgradeSkill
- api-platform-userSkill
- api-platform-versioningSkill
- bootstrap-checkSkill
- brainstormingSkill
- config-env-parametersSkill
- controller-cleanupSkill
- cqrs-and-handlersSkill
- daily-workflowSkill
- doctrine-batch-processingSkill
- doctrine-fetch-modesSkill
- doctrine-fixtures-foundrySkill
- doctrine-migrationsSkill
- doctrine-relationsSkill
- doctrine-transactionsSkill
- effective-contextSkill
- executing-plansSkill
- functional-testsSkill
- interfaces-and-autowiringSkill
- makefile-disciplineSkill
- messenger-retry-failuresSkill
- ports-and-adaptersSkill
- quality-checksSkill
- rate-limitingSkill
- runner-selectionSkill
- strategy-patternSkill
- symfony-cacheSkill
- symfony-messengerSkill
- symfony-schedulerSkill
- symfony-votersSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Write tests extending ApiTestCase with Factories + ResetDatabase traits.
- Very specific: line 27
Run with ./vendor/bin/paratest -p8 in CI for parallel execution.
- Very specific: line 32
Hash algorithm
md5is for tests only: Never in any other env. - Distinctive: line 33
One assertion per scenario: No conditional logic in tests.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
API Platform 4.3 — Functional tests
Use when
- Writing API tests for a new resource / operation.
- Updating older tests still using
hydra:member/hydra:totalItems(broken in 4.x). - Speeding up a slow suite (Foundry → DAMA → ParaTest progression).
- Authenticating clients with JWT for protected endpoints.
- Asserting the JSON-LD schema strictly.
Default workflow
- Install the dev stack —
symfony/test-pack,http-client,browser-kit,justinrainbow/json-schema,dama/doctrine-test-bundle,zenstruck/foundry,brianium/paratest. - Wire DAMA via the PHPUnit extension; configure md5 hashing in
config/packages/test/security.yaml. - Write tests extending
ApiTestCasewithFactories+ResetDatabasetraits. - Cover happy path, 401, 403, 404, 422, ownership, filters, pagination on every operation.
- Run with
./vendor/bin/paratest -p8in CI for parallel execution.
Guardrails
- No
hydra:prefix anywhere in assertions in 4.x. Usemember,totalItems,view,next. - Default page size is 30 in 4.x (not 20 like 3.x). Adapt counts.
- Hash algorithm
md5is for tests only. Never in any other env. - One assertion per scenario. No conditional logic in tests.
- Tests are independent — DAMA transaction rollback or Foundry
ResetDatabaseensures it; never rely on order.
Progressive disclosure
SKILL.mdlists posture and rules.reference.mdcarries the full stack setup, the reusable authenticated client, JWT auth tests, schema assertions, filters + pagination + auth + ownership coverage matrix, scenario-based naming, CI patterns.
Output contract
- Tests in
tests/Functional/Api/extendingApiTestCase(or a project-specificAbstractApiTest). - Each operation covered with happy path + at least one negative case (401/403/404/422).
- Schema assertions on collection and item responses.
- CI invokes
./vendor/bin/paratest -p8.
References
reference.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

