doctrine/data-fixtures
Doctrine Data Fixtures provides a simple way to define, manage, and run data fixture loaders for Doctrine ORM/ODM. Use it to seed databases with reusable sample data for development, testing, and demos via an organized fixture execution workflow.
doctrine/orm or doctrine/dbal). It leverages Laravel’s dependency injection and service container to register fixtures as console commands or migrations.UserFixtures, ProductFixtures), allowing granular control over data loading. Supports ordered execution, references, and conditional loading, which aligns with Laravel’s modular testing and seeding patterns.DryRunORMExecutor for pre-flight validation of fixtures, reducing runtime errors in production-like environments.doctrine/orm).php artisan doctrine:fixtures:load) or integrated into database migrations.EntityManager).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Doctrine Version Lock | Tight coupling with Doctrine ORM/ODM versions (e.g., v2.2.x requires ORM 3.x). | Pin doctrine/orm to a compatible range (e.g., ^3.0) in composer.json. |
| Migration Complexity | Fixtures may override existing data if not purged first. | Use ORMExecutor::PURGE_MODE_TRUNCATE or PURGE_MODE_DELETE explicitly. |
| Performance Overhead | Large fixture sets may slow down CI/CD pipelines. | Implement parallel loading (e.g., via ExecutorInterface overrides) or dry runs. |
| Testing Isolation | Fixtures pollute the test database if not cleaned up. | Use Laravel’s DatabaseTransactions or Doctrine’s Purger in setUp()/tearDown(). |
| Reference Management | Circular references or invalid references can break fixture loading. | Validate references with DryRunORMExecutor before full execution. |
DatabaseSeeder.Purger.DryRunORMExecutor first.DatabaseSeeder or Factory for complex, relational test data.doctrine/migrations).php artisan fixtures:load --env=testing) to load fixtures.FixturesLoader in AppServiceProvider for global access.phpunit.xml with <env name="DB_DUMPER" value="DoctrineFixturesDumper">.| Step | Action | Tools/Commands |
|---|---|---|
| 1. Assess Current State | Audit existing test data strategies (e.g., seeders, factories, SQL files). | composer why-not doctrine/data-fixtures |
| 2. Setup Doctrine | Install doctrine/orm and configure in config/database.php (if not already present). |
composer require doctrine/orm |
| 3. Define Fixtures | Create fixture classes (e.g., database/fixtures/UserFixtures.php) extending Fixture. |
Follow Doctrine Fixtures Docs |
| 4. Register Fixtures | Load fixtures via Artisan or migrations. | php artisan make:command LoadFixturesCommand |
| 5. Integrate with Tests | Replace DatabaseSeeder with fixture loading in phpunit.xml or setUp(). |
<env name="DB_DUMPER" value="DoctrineFixturesDumper"> |
| 6. CI/CD Pipeline | Add fixture loading to CI workflows (e.g., GitHub Actions). | php artisan fixtures:load --env=ci |
doctrine/doctrine-bundle.UserFixtures, RoleFixtures).DryRunORMExecutor to validate references before full execution.setUp() or DatabaseTransactions.migrate:fresh --seed).doctrine/data-fixtures to a specific version (e.g., ^2.2) to avoid breaking changes.ExecutorInterface::setLogger() to log fixture execution.--verbose) for Artisan commands to trace issues.DryRunORMExecutor.How can I help you explore Laravel packages today?