/test-writing:phpunit-integration-test-generationfrom test-writing
Generates Shopware 6 integration tests for classes requiring wired-up code (controllers, indexers, message handlers, scheduled tasks, DAL flows). Uses IntegrationTestBehaviour against the real DAL, container, and HTTP/messaging. Skips unit-shaped classes and defers to unit test generation.
Ships in test-writing. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Generate Shopware-compliant PHPUnit integration tests that exercise wired-up code through IntegrationTestBehaviour, produce integration-shape assertions, and pass PHPStan and PHPUnit validation.
Write ONLY to:
tests/integration/** — Integration test filesNEVER write to:
src/** — Source code (read-only)tests/unit/** — Out of scope (use phpunit-unit-test-generation)tests/migration/** — Out of scope (use phpunit-migration-test-generation)digraph integration_test_generation {
"User invocation" [shape=doublecircle];
"Validate input" [shape=box];
"Source is PHP class in src/?" [shape=diamond];
"Analyze source" [shape=box];
"Integration pattern detected?" [shape=diamond];
"Select template + apply" [shape=box];
"Write test file" [shape=box];
"Validate (PHPStan, PHPUnit, ECS)" [shape=box];
"All green?" [shape=diamond];
"Fix iteration (max 3)" [shape=box];
"Iterations exhausted?" [shape=diamond];
"Report SUCCESS" [shape=doublecircle];
"Report PARTIAL" [shape=doublecircle];
"Report SKIPPED (defer to unit gen)" [shape=doublecircle];
"Report FAILED" [shape=doublecircle];
"User invocation" -> "Validate input";
"Validate input" -> "Source is PHP class in src/?";
"Source is PHP class in src/?" -> "Report FAILED" [label="no"];
"Source is PHP class in src/?" -> "Analyze source" [label="yes"];
"Analyze source" -> "Integration pattern detected?";
"Integration pattern detected?" -> "Report SKIPPED (defer to unit gen)" [label="no — unit-shape SUT"];
"Integration pattern detected?" -> "Select template + apply" [label="yes"];
"Select template + apply" -> "Write test file";
"Write test file" -> "Validate (PHPStan, PHPUnit, ECS)";
"Validate (PHPStan, PHPUnit, ECS)" -> "All green?";
"All green?" -> "Report SUCCESS" [label="yes"];
"All green?" -> "Iterations exhausted?" [label="no"];
"Iterations exhausted?" -> "Report PARTIAL" [label="yes"];
"Iterations exhausted?" -> "Fix iteration (max 3)" [label="no"];
"Fix iteration (max 3)" -> "Validate (PHPStan, PHPUnit, ECS)";
}
src/If validation fails, return FAILED with reason.
Read the source class and detect which integration pattern applies. See references/source-analysis.md for the full detection logic.
#[Package('...')] value for the test class — an integration test carries no #[CoversClass] target, so take the value from the nearest src/ directory the test path mirrors, walking up until one exists and using the value its .php files carry. When that yields no value, emit no #[Package] and report that in the Phase 5 report's Package field (none, per references/output-format.md) rather than guessing a value.Core, Administration, Storefront, Elasticsearch)Walk the decision table in references/source-analysis.md. Patterns are evaluated top to bottom; the first match wins.
| Pattern | Indicator |
|---|---|
controller | Extends AbstractController or AbstractRoute / Abstract*Route, or methods carry #[Route] |
scheduled-task | Extends ScheduledTaskHandler, OR has #[AsMessageHandler] and the __invoke() parameter is a ScheduledTask subclass |
message-handler | Has #[AsMessageHandler] on __invoke() AND the parameter is a domain message (not a ScheduledTask) |
indexer | Extends EntityIndexer (Shopware) |
dal-flow | Constructor takes EntityRepository AND public methods write through it (create, update, upsert) AND the SUT contract is "the data was persisted" or "the indexer/event was triggered" |
multi-service | Constructor takes ≥ 3 non-boundary dependencies (boundary set defined in INTEGRATION-002), and at least 2 are stateful (DAL, indexer, event dispatcher, system config) |
skip_type: unit_test_more_appropriate and reason: "Source class fits a unit-shape pattern (no persistence, no wiring, no multi-service coordination under test). Use phpunit-unit-test-generation instead." Reference the relevant refactoring pattern in phpunit-integration-to-unit-migrating/references/refactoring-patterns.md when the SUT looks like a factory, compiler pass, single subscriber, parser, constraint-only validator, or DAL materializer.Mirror source path with src/ → tests/integration/:
src/Core/Content/Product/ProductIndexer.php → tests/integration/Core/Content/Product/ProductIndexerTest.phpsrc/Core/Checkout/Cart/SalesChannel/CartLoadRoute.php → tests/integration/Core/Checkout/Cart/SalesChannel/CartLoadRouteTest.phpNamespace mirrors the path: Shopware\Tests\Integration\Core\Content\Product.
Use the integration test template at templates/integration-test.md. The template has a base block plus one conditional section per pattern. Include exactly one pattern section based on Phase 2 detection. The base block defers all behavior trait use statements to the conditional section, because the trait choice varies by pattern:
#[Package], @internal, empty class shell — no #[CoversClass] (integration tests carry none by convention)controller: IntegrationTestBehaviour + SalesChannelApiTestBehaviour (or admin/storefront equivalent), IdsCollection, KernelBrowser built via createCustomSalesChannelBrowser([...]), #[Group('store-api')], request invocation, response assertionsscheduled-task: DatabaseTransactionBehaviour + KernelTestBehaviour (lighter than IntegrationTestBehaviour), parent::setUp(), direct $handler->run() invocation, raw SQL Connection::fetchOne(...) assertionsmessage-handler: IntegrationTestBehaviour, direct ($this->handler)($message) invocation, DAL read-back assertion (bus dispatch only when transport routing is part of the SUT contract)indexer: DatabaseTransactionBehaviour + KernelTestBehaviour, parent::setUp(), realtime flow — write via DAL captures $event, $indexer->update($event) returns ?EntityIndexingMessage, assert on the returned message's datadal-flow: IntegrationTestBehaviour, arrange prerequisite state via DAL, invoke SUT, assert persisted result via separate DAL readmulti-service: IntegrationTestBehaviour composed with domain behaviours per dependency (AppSystemTestBehaviour, GuzzleTestClientBehaviour, MailTemplateTestBehaviour), configure inputs through SystemConfigService / DAL, invoke SUT, assert effects across multiple collaboratorsFill placeholders using Phase 2 metadata. Use IdsCollection (Shopware\Core\Test\Stub\Framework\IdsCollection) for any test that manages more than one entity ID, and type all repository properties with the generic PHPDoc @var EntityRepository<XxxCollection>. Leave TODO: markers where the behavior-specific arrange or assertion is genuinely SUT-dependent and not derivable from class structure — these are the spots a human or follow-up step must complete.
The generated test must satisfy all INTEGRATION-001..008 rules at write time. Self-check before validation:
use IntegrationTestBehaviour; present#[Depends] between test methodsmarkTestSkipped for missing fixtures — create themWrite to the path determined in Step 1.
- [ ] PHPStan passes (0 errors)
- [ ] PHPUnit passes (all tests green)
- [ ] ECS passes (code style)
{
"paths": ["tests/integration/Path/To/GeneratedTest.php"],
"error_format": "json"
}
Common integration test errors:
IntegrationTestBehaviour, Context, Uuid, TestDefaults, Criteriastatic::getContainer()->get(...) results — use assert($x instanceof Foo) or PHPDoc when the container returns the abstract typeEntityRepository — verify the entity repository service id{
"paths": ["tests/integration/Path/To/GeneratedTest.php"],
"output_format": "result-only"
}
If tests fail, re-run without output_format to get failure details.
Common integration test failures:
tearDown() (INTEGRATION-003)markTestSkipped triggered by missing fixtures — replace with fixture creation (INTEGRATION-006)Check for violations, then apply fixes if needed.
Loop Steps 1-5 until all validations pass. Maximum 3 iterations — after that, proceed to Phase 5 with status PARTIAL.
For output format and examples, see references/output-format.md.
| Condition | Status | skip_type |
|---|---|---|
| All validations pass | SUCCESS | — |
| Test generated, validation issues remain after 3 iterations | PARTIAL | — |
| Source class is unit-shape (no integration pattern matched) | SKIPPED | unit_test_more_appropriate |
| Invalid input (not a PHP class, file not found, not in src/) | FAILED | — |
What SKILL.md sets; muted values are Claude Code's defaults
test-writing:test-generator), in the backgroundnpx claudepluginhub shopwarelabs/ai-coding-tools --plugin test-writing11 skills in this plugin
/phpunit-integration-test-reviewingInternal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent./phpunit-integration-to-unit-migratingUse this skill ONLY when the user explicitly requests an audit, migration, or evaluation of whether a Shopware integration test belongs in the unit suite — trigger phrases like "audit integration tests", "migrate integration tests to unit", "is this an integration test or a unit test", "evaluate integration tests for migration", "should this be a unit test instead". Audits tests under tests/integration/ for misplacement and migrates load-bearing-free tests to tests/unit/ using one of six codified refactoring patterns. NOT invoked automatically by reviewing skills — phpunit-integration-test-reviewing emits a placement smoke-alarm hint pointing here, but the user must invoke this skill explicitly to run the deep audit./phpunit-migration-test-generationUse this skill when the user asks to generate, write, or create migration tests for a Shopware 6 migration class — phrases like "generate migration tests", "write a migration test", "create migration test", "test this migration", "test Migration1234Foo". Analyzes the source migration's SQL operations to pick an appropriate pattern (schema-add, schema-remove, data-update, config, mail template), then generates a test that runs against a real database and passes PHPStan and PHPUnit validation. Do NOT activate for unit tests (use phpunit-unit-test-writing) or integration tests of non-migration source classes (use phpunit-integration-test-generation).Other plugins' skills for the same job