Logo van Phpunit Unit Test Generation

Phpunit Unit Test Generation

Organisatie
shopwareLabs
phpunit-unit-test-generation

Internal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent.

Overzicht

UitgevershopwareLabs
Repositoryai-coding-tools
Skillnaamphpunit-unit-test-generation
Sterren
45
Forks
7
Meegeleverde bestanden
15
LicentieMIT
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • 15 meegeleverde bestanden

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. Bestanden zijn alleen-lezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door shopwareLabs op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Phpunit Unit Test Generation in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/shopwareLabs/ai-coding-tools/tree/main/plugins/test-writing/skills/phpunit-unit-test-generation
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/shopwareLabs/ai-coding-tools.git /tmp/ai-coding-tools
mkdir -p .claude/skills
cp -r /tmp/ai-coding-tools/plugins/test-writing/skills/phpunit-unit-test-generation .claude/skills/phpunit-unit-test-generation
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Phpunit Unit Test Generation in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Phpunit Unit Test Generation automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Phpunit Unit Test Generation niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

PHPUnit Test Generation

Generate Shopware-compliant PHPUnit unit tests that pass PHPStan and PHPUnit validation.

File Write Restrictions

Write ONLY to:

  • tests/unit/** - Unit test files

NEVER write to:

  • src/** - Source code (read-only)
  • tests/integration/** - Out of scope
  • Any other directory

Quick Start

  1. Read the target source class
  2. Check if test is required (see Phase 1)
  3. Determine test category (A-E)
  4. Apply the matching template
  5. Validate with PHPStan and PHPUnit
  6. Fix any errors and repeat
  7. Generate completion report

Phase 1: Analyze Source Class

Step 1: Check Coverage Exclusions

Before analyzing the source class, check if the project's phpunit.xml.dist (or phpunit.xml) excludes it from coverage. Files excluded from coverage do not need unit tests.

  1. Read phpunit.xml.dist from the project root
  2. Find <exclude> rules inside the <coverage> or <source> section
  3. Match the source file path against each rule:
    • <directory suffix="X">path</directory> — excluded if file is under path AND filename ends with X
    • <file>path/to/File.php</file> — excluded if relative path matches exactly
  4. If excluded → Return SKIPPED with skip_type: coverage_excluded and reason: "Source file excluded from coverage by phpunit.xml.dist (<matched-rule>)"

If phpunit.xml.dist is not found, skip this step.

Step 2: Determine If Test Is Required

Before generating any test, evaluate if the class/method requires one.

Quick check: Does the method body contain ONLY return <literal|constant|property|passthrough-new|delegation>?

  • Yes -> NO TEST NEEDED — Return SKIPPED with skip_type: no_logic and reason describing the pattern (e.g., "Pure accessor - no logic to test")
  • No (has conditionals/loops/transformations) -> Continue to Step 3

For detailed rules on what to test vs skip, see references/test-requirement-rules.md.

Step 3: Analyze Source Structure

Read the target class to determine:

  1. Public methods - What behaviors to test
  2. Constructor dependencies - What to mock/stub
  3. Return types - Expected outcomes
  4. Exception scenarios - Error paths (see references/exception-patterns.md)
  5. Deprecation markers - @deprecated tags, Feature::triggerDeprecationOrThrow(), Feature::silent(), Feature::callSilentIfInactive() (see references/deprecation-guards.md)
  6. Package attribute - the #[Package('...')] value the covered class carries. The test class carries the same value. When the covered class carries none, 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.

Step 4: Detect Category

Use the decision tree to select the appropriate category:

Has constructor dependencies?
├── No → Is it an Exception class?
│   ├── Yes → Category E
│   └── No → Category A (DTO)
└── Yes → Uses EntityRepository?
    ├── Yes → Category D (DAL)
    └── No → Implements EventSubscriberInterface or FlowAction?
        ├── Yes → Category C (Flow/Event)
        └── No → Category B (Service)

For detailed category criteria, see references/category-detection.md.


Phase 2: Essential Rules

Apply these mandatory conventions when generating tests.

Quick Reference

RuleRequirement
File locationtests/unit/ mirroring src/ path
Class attributes#[Package('...')] then #[CoversClass(TargetClass::class)], both required
AssertionsUse static:: not $this->
Base classExtend PHPUnit\Framework\TestCase
Method namingtest + Action + Condition + ExpectedResult
Attribute orderPHPDoc -> DataProvider -> TestDox -> method
One behaviorNO conditionals in tests

TestDox Phrasing

TestDox MUST be a predicate phrase starting with an action verb:

  • Good: "creates product", "returns null", "throws exception"
  • Bad: "It creates...", "Should return...", "Tests that..."

Mocking Priority

  1. Real implementation - Use actual objects when simple
  2. Shopware stubs - StaticEntityRepository, StaticSystemConfigService, Generator
  3. PHPUnit mocks - Only for external/IO dependencies

For createStub vs createMock selection, see references/mocking-patterns.md.

For complete rules, see references/essential-rules.md.


Phase 3: Generate Test

Step 1: Select Template

Based on category from Phase 1:

CategoryTemplate
A (DTO)templates/category-a-dto.md
B (Service)templates/category-b-service.md
C (Flow/Event)templates/category-c-flow.md
D (DAL)templates/category-d-dal.md
E (Exception)templates/category-e-exception.md

For data provider and decoration contract patterns, see references/common-patterns.md.

Step 2: Replace Placeholders

  • {package} - #[Package] value from Phase 1 Step 3 (e.g., framework, discovery)
  • {Module} - Core module (e.g., Content, Checkout, System)
  • {Submodule} - Submodule path (e.g., Product, Cart\LineItem)
  • {TargetClass} - Class name being tested
  • {Entity} - Entity name for DAL tests
  • {Method} - Method name being tested
  • {Expected} - Expected outcome description
  • {Condition} - Condition description
  • {Exception} - Exception class name

Step 3: Write Test File

Write to correct location: tests/unit/{path matching src}/{ClassName}Test.php


Phase 4: Validate and Fix

Validation Loop

- [ ] PHPStan passes (0 errors)
- [ ] PHPUnit passes (all tests green)
- [ ] ECS passes (code style)

Step 1: Run PHPStan

json
{
  "paths": ["tests/unit/Path/To/GeneratedTest.php"],
  "error_format": "json"
}

Zero errors = pass.

Step 2: Fix PHPStan Errors

Apply fixes for common errors. See references/validation-error-mapping.md.

Step 3: Run PHPUnit

json
{
  "paths": ["tests/unit/Path/To/GeneratedTest.php"],
  "output_format": "result-only"
}

All tests passing = success. If tests fail, re-run without output_format to get failure details for Step 4.

Step 4: Fix Test Failures

Apply fixes for common failures. See references/validation-error-mapping.md.

Step 5: Run ECS Check and Fix

Check for violations, then apply fixes if needed.

Repeat Until Pass

Loop through Steps 1-5 until all validations pass.

Maximum iterations: Stop after 3 failed attempts and proceed to Phase 5.


Phase 5: Generate Report

For output format and examples, see references/output-format.md.

Status Determination

ConditionStatusskip_type
All validations passSUCCESS—
Test generated, validation issues remain after 3 iterationsPARTIAL—
File excluded from coverage in phpunit.xml.distSKIPPEDcoverage_excluded
No testable logic (per Test Requirement Rules)SKIPPEDno_logic
Invalid input (not a PHP class, file not found)FAILED—

Report Contents

  1. Summary: Source path, test path, status, category, package (or none when derivation yielded no value)
  2. Generation Details: Test method count, template used
  3. Validation Results: PHPStan/PHPUnit/ECS pass/fail counts
  4. Remaining Issues (if PARTIAL): Location, error, status table

Additional Resources

Reference Files

For detailed patterns and techniques, consult:

  • references/test-requirement-rules.md - Decision tree for what to test
  • references/category-detection.md - How to categorize source classes
  • references/essential-rules.md - Naming, attribute, structure rules
  • references/validation-error-mapping.md - Error codes and fixes
  • references/shopware-stubs.md - StaticEntityRepository, Generator patterns
  • references/exception-patterns.md - expectExceptionObject, expectException + message, exception codes
  • references/mocking-patterns.md - createStub vs createMock, intersection types, configuration, side-effect verification
  • references/deprecation-guards.md - DisabledFeatures, skipTestIfActive/InActive, Feature::silent, class-level guards
  • references/common-patterns.md - Data providers, AAA structure, event subscribers, decoration pattern
  • references/output-format.md - Report output contract

Templates

Category-specific test generation templates in templates/:

  • category-a-dto.md - Simple DTO/Entity tests
  • category-b-service.md - Service tests with dependencies
  • category-c-flow.md - Flow/Event subscriber tests
  • category-d-dal.md - DAL/Repository tests
  • category-e-exception.md - Exception handling tests

Meegeleverde bestanden

Het model leest deze bestanden wanneer nodig terwijl de skill geladen is. Ze worden beschikbaar gesteld als leesbare bestanden en worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Phpunit Unit Test Generation?

Internal sub-skill. Do not auto-activate. Use only when explicitly invoked by name by another skill or agent.

Waarom Phpunit Unit Test Generation gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Phpunit Unit Test Generation bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Phpunit Unit Test Generation in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/shopwareLabs/ai-coding-tools/tree/main/plugins/test-writing/skills/phpunit-unit-test-generation. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Phpunit Unit Test Generation gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Phpunit Unit Test Generation gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Phpunit Unit Test Generation ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Phpunit Unit Test Generation gratis?

Ja. Deze skill is door shopwareLabs op GitHub gepubliceerd onder de licentie MIT. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇