frameworkmakefactory

Génère Factory Foundry pour tests

⭐6stars🔀0forks📁View on GitHub🕐Updated Jan 2, 2026

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.
nameframework:make:factory
descriptionGénère Factory Foundry pour tests
licenseMIT
version1.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

  1. Demander le nom de l'entité (EntityName)
  2. Vérifier que l'entité existe
  3. Lire l'entité pour détecter les propriétés du constructeur create()
  4. Générer la factory depuis le template templates/Factory/
  5. 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() avec instantiateWith() appelant Entity::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 de new Entity())
  • Faker via self::faker()
  • Méthodes custom uniquement si demandées (YAGNI)
  • Persiste par défaut, withoutPersisting() si besoin