doctrine-fixtures/data-generation-bundle
Pros:
construct: true), enabling realistic entity relationships (e.g., Article requiring a User author).Cons:
config/bundles.php).DatabaseSeeder).hasMany/belongsTo conventions; relationships must be manually configured in YAML.bcrypt) not handled automatically—requires custom logic in fixtures.phpunit-db or factory_boy for integration tests, but lacks transaction rollback or parallel test support.php artisan generate:fixtures).spatie/factories + laravel-shift/database-seeder).laravel-shift/database-seeder (built-in, Eloquent-aware).spatie/laravel-factories (factory-based, more flexible).orchestra/testbench (for testing-specific fixtures).fillable/guarded attributes?
Illuminate\Database\Eloquent\SoftDeletes)?
deleted_at is supported.DatabaseTransactions trait for test rollbacks?spatie/laravel-factories instead).// app/Console/Commands/GenerateFixtures.php
use DoctrineFixtures\DataGenerationBundle\Command\GenerateFixturesCommand;
class GenerateFixtures extends Command {
protected $signature = 'fixtures:generate';
public function handle() {
$this->call(GenerateFixturesCommand::class);
}
}
spatie/factories or laravel-shift/database-seeder.HasFactory, Observables).FormRequest or Validator.created, updated model events.Article → User author).php artisan fixtures:generate in test suites).fixtures-config.yml) reduces duplication.chunk()).spatie/laravel-factories).| Scenario | Impact | Mitigation |
|---|---|---|
| Bundle update breaks | Fixtures fail silently | Pin version in composer.json |
| Doctrine/Eloquent mismatch | Data corruption | Use transactions + rollback |
| Custom logic errors | Invalid test data | Validate fixtures post-generation |
| CI/CD flakiness | Tests fail intermittently | Cache fixtures or use Docker resets |
namespace/construct YAML syntax.phpunit.xml:
<php>
<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="sqlite_testing"/>
</php>
<listeners>
<listener class="Illuminate\Foundation\Testing\DatabaseTransactions"/>
<listener class="App\Listeners\GenerateFixturesBeforeTests"/>
</listeners>
How can I help you explore Laravel packages today?