acc-create-test-builder
Test Data Builder Generator
Generates Test Data Builder and Object Mother patterns for test data creation.
Patterns
Test Data Builder
Fluent interface for constructing test objects with customizable properties.
When to use:
- Complex objects with many properties
- Need to customize specific properties per test
- Want to express test intent clearly
Object Mother
Factory methods returning pre-configured objects for common scenarios.
When to use:
- Standard test fixtures (default user, pending order)
- Shared across many tests
- Named scenarios (premium customer, expired subscription)
References
references/templates.md— Builder and Object Mother class templatesreferences/examples.md— Complete Order example with Value Object builders and usage
Generation Instructions
-
Analyze the target class:
- Constructor parameters
- Required vs optional properties
- Value objects used
- State transitions (for entities)
-
Determine sensible defaults:
- Generate IDs automatically
- Use common/valid values
- Consider relationships
-
Create Builder with:
- Private constructor with defaults
- Static factory method (
aOrder,anEmail) with*methods for each property- Immutable (clone in each method)
build()method
-
Create Mother with:
default()method- Named scenarios (
pending,confirmed,premium) - Parameterized methods (
forCustomer,withTotal)
-
File placement:
- Builders:
tests/Builder/{ClassName}Builder.php - Mothers:
tests/Mother/{ClassName}Mother.php
- Builders:
Best Practices
- Sensible defaults — Tests should work without customization
- Fluent interface — Chain method calls
- Immutable builders — Clone in each
with*method - Expressive names —
pending()notwithStatus(pending) - Composition — Builders can use other Mothers/Builders
- Single Responsibility — One builder per aggregate/entity
More from dykyi-roman/awesome-claude-code
psr-overview-knowledge
PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.
22detect-code-smells
Detects code smells in PHP codebases. Identifies God Class, Feature Envy, Data Clumps, Long Parameter List, Long Method, Primitive Obsession, Message Chains, Inappropriate Intimacy. Generates actionable reports with refactoring recommendations.
15clean-arch-knowledge
Clean Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Clean Architecture and Hexagonal Architecture audits.
15ddd-knowledge
DDD architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Domain-Driven Design audits.
14testing-knowledge
Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.
12bug-root-cause-finder
Root cause analysis methods for PHP bugs. Provides 5 Whys technique, fault tree analysis, git bisect guidance, and stack trace parsing.
12