phpunit-unit-test-writing
Use this skill when the user asks to write, generate, create, or add PHPUnit unit tests for a Shopware 6 source class — phrases like "write unit tests for X", "generate tests for ClassName", "create PHPUnit tests", "add test coverage", "test this class", "cover this with tests", "I need tests for", "unit test this", "SW6 unit tests", "Shopware unit tests", "PHPUnit tests for Shopware". Orchestrates the full workflow — source-class category detection (DTO, Service, Flow/Event, DAL, Exception), test generation, MCP-driven review against Shopware unit-test rules, and an inline fix loop that iterates until tests pass. Do NOT activate for integration tests (use phpunit-integration-test-generation), migration tests (use phpunit-migration-test-generation), e2e tests, or non-PHP testing.
What this skill does
# PHPUnit Unit Test Writing
Orchestrates the complete workflow for generating and reviewing Shopware 6 unit tests.
## Core Principle
Execute immediately. Report work AFTER completion, never before.
---
## Execution Strategy
### Single File Input
Process the complete workflow (Generate → Coverage Exclusion → Review → Fix → Report) for that one file.
### Multiple Files / Directory Input
Process files sequentially — one file at a time:
```
FOR EACH source file:
1. Generate test (wait for completion)
2. Review test (wait for completion)
3. Fix loop if needed (wait for completion)
4. Mark file complete
5. Collapse intermediate state to compact summary
THEN proceed to next file
```
After each file completes all phases, collapse intermediate state (generation details, review iterations, fix attempts) to a compact summary before proceeding to the next file. This prevents context growth on multi-file runs.
---
## Autonomous Execution Rules
- No previewing — Never list tests you're about to create
- No confirmation — Never ask "should I start?" or "should I proceed?"
- Immediate action — Invoke Skill tools without hesitation
- Report after — Only explain results, not intentions. This applies to communication only — never skip workflow phases
- No phase skipping — Every phase whose entry condition is met MUST execute
---
## File Write Restrictions
- Generation: handled by generation skill (Write tool in forked context)
- Fix loop: handled by orchestrator (Edit tool for targeted fixes)
- Coverage config: handled by orchestrator (Edit tool, Phase 2 only, user-confirmed)
Never modify:
- `src/**` — Source code
- `tests/integration/**` — Integration tests (out of scope)
- Any directory other than `tests/unit/**`
Conditional modification (user confirmation required):
- `phpunit.xml.dist` — Only adding `<file>` entries to `<exclude>` section, only during Phase 2
---
## Workflow Phases
### Phase 1: Test Generation
1. **Identify** the source class requiring tests
2. **Invoke generation skill**:
```
Skill(test-writing:phpunit-unit-test-generation) with source: {source_class_path}
```
3. **Parse response** for:
- `test_path`: Location of generated test file
- `status`: SUCCESS | PARTIAL | FAILED | SKIPPED
- `category`: A | B | C | D | E (test complexity category)
- `skip_type`: `coverage_excluded` | `no_logic` (only when SKIPPED)
4. **Decision**:
- FAILED → Report reason to user, end workflow
- SKIPPED with `skip_type: coverage_excluded` → Report reason to user, end workflow
- SKIPPED with `skip_type: no_logic` → Proceed to Phase 2 (Coverage Exclusion Offer)
- SUCCESS or PARTIAL → Proceed to Phase 3
5. **Update workflow state** on SUCCESS/PARTIAL:
```
TodoWrite([
{content: "Generate unit tests", status: "completed", activeForm: "Generating unit tests"},
{content: "Review unit tests", status: "in_progress", activeForm: "Reviewing unit tests"}
])
```
### Phase 2: Coverage Exclusion Offer
Entry condition: Generator returned SKIPPED with `skip_type: no_logic`.
Source files with no testable logic still appear as 0% in coverage reports unless excluded. This phase offers to add them to `phpunit.xml.dist` so coverage reports only show files that actually need testing.
#### Single-File Mode
1. **Read** `phpunit.xml.dist` from the project root (fallback: `phpunit.xml`)
2. If not found → report SKIPPED normally, end workflow
3. **Locate** the `<exclude>` section within `<coverage>/<source>` (or `<source>`)
4. **Verify** the source file is not already excluded (guard check)
5. **Ask** via AskUserQuestion:
```
{source_path} was skipped — no testable logic detected ({reason}).
Add it to phpunit.xml.dist coverage exclusions so it doesn't show as uncovered?
```
Options: "Yes, exclude from coverage" / "No, skip"
6. **If approved**:
- If `<exclude>` section exists → Use Edit to add `<file>{relative_path}</file>` before `</exclude>`
- If no `<exclude>` section → Use Edit to insert `<exclude><file>{relative_path}</file></exclude>` before `</source>`
- Record: `coverage_excluded: true`
7. **If declined** → Record: `coverage_excluded: false`
8. Report SKIPPED with coverage action taken, end workflow
#### Multi-File Mode
Do NOT prompt per file. Instead, collect all `skip_type: no_logic` files across the batch. After all files complete their workflow phases, present a single batch prompt:
```
X files were skipped — no testable logic detected.
Add them to phpunit.xml.dist coverage exclusions?
- src/Core/Content/Product/ProductEntity.php (Pure accessor)
- src/Core/Content/Category/CategoryCollection.php (Simple collection)
```
Options: "Yes, exclude all from coverage" / "No, skip"
If approved, add all `<file>` entries in a single Edit operation.
---
### Phase 3: Review
MUST execute when generator returned SUCCESS or PARTIAL. Never skip.
1. **Invoke reviewing skill**:
```
Agent(
agent: "test-writing:test-reviewer",
prompt: "Invoke Skill(test-writing:phpunit-unit-test-reviewing) for {test_path}. Return the structured report."
)
```
2. **Parse response**:
- `status`: PASS | NEEDS_ATTENTION | ISSUES_FOUND | FAILED
- `errors`: Remaining must-fix rules (mandatory compliance failures)
- `warnings`: Remaining should-fix rules (optional improvements)
3. **Decision**:
| Status | Action |
|--------|--------|
| PASS | Proceed to Phase 6 (Final Report) with status COMPLIANT |
| NEEDS_ATTENTION | Proceed to Phase 4 (Fix Loop) for warnings, then Phase 5 for any unresolved |
| ISSUES_FOUND | Proceed to Phase 4 (Fix Loop) |
| FAILED | Report failure reason, end workflow |
### Phase 4: Fix Loop (max 4 iterations)
Entry condition: Review returned ISSUES_FOUND (has must-fix errors).
The loop continues until ALL errors are resolved — both tool validation errors AND semantic review errors (must-fix rules from reviewing skill).
```
FOR iteration 1 to 4:
1. Apply ALL fixes from review report errors (Edit tool)
2. Run validation tools (code style, static analysis, tests)
3. Re-invoke reviewing skill to check for remaining issues
4. Track issue history for oscillation
5. Check exit conditions (PASS = 0 errors from review AND tools)
↓
Return final result
```
#### Step 1: Apply Fixes
For each must-fix rule with suggested fix from the review report:
1. Read current file content
2. Apply fix using Edit tool
3. Log: `{rule_id, location, attempted: true, applied: true/false, reason: null}`
Priority order when fixes conflict:
1. Structural errors (conditionals, class structure) — often require major changes
2. Redundancy errors — may remove/merge tests
3. Ordering errors — reorder test methods
4. Other must-fix rules in code order
#### Step 2: Validate
Run code style fix, static analysis, and tests on `{test_path}`. Fix any errors before continuing.
#### Step 3: Re-invoke Reviewing Skill
```
Agent(
agent: "test-writing:test-reviewer",
prompt: "Invoke Skill(test-writing:phpunit-unit-test-reviewing) for {test_path}. Return the structured report."
)
```
Spawns test-reviewer agent → returns updated report with errors/warnings.
#### Step 4: Track Issue History
Maintain issue history for oscillation detection:
```yaml
issue_history:
- iteration: 1
issues: ["{rule_id}:45", "{rule_id}:67"]
- iteration: 2
issues: ["{rule_id}:12"]
- iteration: 3
issues: ["{rule_id}:45"] # same rule:line returned — oscillation!
```
Oscillation Detection:
- Track `{rule_id}:{line_number}` per iteration
- If same issue appears in non-consecutive iterations → oscillation detected
- Example: {rule_id}:45 in iter 1, fixed in iter 2, returns in iter 3 = oscillation
#### Step 5: Exit Conditions
| Condition | Action |
|-----------|--------|
| Review returns 0 errors AND tools pass | Exit with `status: PASS` |
| Oscillation detected | Handle per references/oscillation-handling.md |
| Same errors 2x consecutively | Exit as stuck loop wiRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.