frameworkmakefactory
Génère Factory Foundry pour tests
When & Why to Use This Skill
The framework:make:factory Claude skill automates the generation of Zenstruck Foundry factories for PHP entities, specifically designed for Symfony environments. By analyzing existing entities, it creates standardized, high-quality factory classes that follow Elegant Objects principles and utilize Faker for realistic data generation. This skill significantly reduces boilerplate code and accelerates the setup of robust automated testing suites.
Use Cases
- Rapid Test Setup: Automatically generate a Foundry factory for a new 'Product' or 'Order' entity, allowing developers to immediately start writing functional tests without manual boilerplate.
- Data Consistency: Ensure all test factories across a project follow the same architectural patterns, such as using 'instantiateWith()' and 'PersistentObjectFactory' for better maintainability.
- Mock Data Automation: Populate entity defaults with localized Faker data automatically, simplifying the creation of complex database states for integration and unit testing.
- Legacy Code Refactoring: Quickly create factories for existing entities to improve test coverage in older codebases that lack structured data fixtures.
| name | framework:make:factory |
|---|---|
| description | Génère Factory Foundry pour tests |
| license | MIT |
| version | 1.0.0 |
Framework Make Factory Skill
Description
Génère une Factory Foundry pour créer des instances d'entités dans les tests.
Usage
Use skill framework:make:factory
Variables requises
- {EntityName} - Nom de l'entité en PascalCase (ex: Product)
- {entityName} - Nom de l'entité en camelCase (ex: product)
- {namespace} - Namespace du projet (défaut: App)
- {properties} - Liste des propriétés pour
defaults()
Dépendances
- Entité dans
src/Entity/{EntityName}.php - Zenstruck Foundry installé
Outputs
src/Factory/{EntityName}Factory.php
Workflow
- Demander le nom de l'entité (EntityName)
- Vérifier que l'entité existe
- Lire l'entité pour détecter les propriétés du constructeur
create() - Générer la factory depuis le template
templates/Factory/ - Afficher le fichier créé
Patterns appliqués
- Extends PersistentObjectFactory, classe
final - Méthode
class()retournant FQCN - Méthode
defaults()avec valeurs Faker - Méthode
initialize()avecinstantiateWith()appelantEntity::create() - Méthodes custom (ex:
withSpecificId(),inactive())
References
- Usage - Exemples de tests et valeurs Faker recommandées
Notes
- Utilise
instantiateWith()pour respecter Elegant Objects (pas denew Entity()) - Faker via
self::faker() - Méthodes custom uniquement si demandées (YAGNI)
- Persiste par défaut,
withoutPersisting()si besoin