andreybolonin/doctrine-fixtures-generator-bundle
Pros:
doctrine/orm and doctrine/doctrine-bundle), making it a natural fit for projects leveraging Doctrine for database abstraction (e.g., legacy Symfony/Lumen bridges, hybrid PHP stacks, or Laravel apps with Doctrine ORM).laravel/factories or fzaninotto/faker are limited to synthetic data. This bundle enables real-world data extraction for testing, migrations, or seed scripts.Cons:
Command in Laravel’s Console\Command).config/fixtures.php).fruitcake/laravel-doctrine or manual setup (Doctrine ORM + Symfony’s doctrine-bundle).Command can be wrapped in Laravel’s Artisan::command() or extended via a custom facade.// app/Console/Commands/GenerateFixtures.php
use Symfony\Component\Console\Command\Command;
use Webonaute\DoctrineFixturesGeneratorBundle\Command\GenerateFixturesCommand;
class GenerateFixtures extends Command {
protected function getSymfonyCommand(): GenerateFixturesCommand {
return new GenerateFixturesCommand();
}
}
DatabaseSeeder or Doctrine’s FixturesLoader.DB::seed() may not natively support Doctrine fixtures; requires custom loader or hybrid approach.@ORM\Entity + Eloquent traits).Console, DependencyInjection) that may not be needed elsewhere in the Laravel app.--help flags) may differ from Laravel’s Artisan conventions.EntityManager and fixture directories.DB::table()->get() + custom fixture generators (e.g., using spatie/fractal) achieve similar goals with less overhead?fruitcake/laravel-doctrine or manual setup).doctrine/doctrine-fixtures-bundle) for loading generated fixtures.FixturesLoader + Laravel’s Seeder).fruitcake/laravel-doctrine or manually configure Doctrine ORM.@ORM\Entity) and Eloquent (if hybrid).config/doctrine.php:
'doctrine' => [
'orm' => [
'entity_managers' => [
'default' => [
'connection' => 'default',
'mappings' => [
'App' => ['is_bundle' => false, 'dir' => 'app/Models'],
],
],
],
],
],
composer require webonaute/doctrine-fixtures-generator-bundle
config/app.php (if using Symfony’s Bundle system) or wrap commands in Laravel’s Artisan.// app/Console/Commands/GenerateDoctrineFixtures.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Webonaute\DoctrineFixturesGeneratorBundle\Command\GenerateFixturesCommand;
class GenerateDoctrineFixtures extends Command {
protected $signature = 'fixtures:generate
{entity : The entity name to generate fixtures for}
{--ids= : Comma-separated IDs to include}
{--output= : Output directory for fixtures}';
public function handle() {
$symfonyCommand = new GenerateFixturesCommand();
$symfonyCommand->setLaravel($this); // Custom adapter
return $symfonyCommand->run(new \Symfony\Component\Console\Input\ArrayInput([
'command' => 'fixtures:generate',
'entity' => $this->argument('entity'),
'--ids' => $this->option('ids'),
'--output' => $this->option('output'),
]), new \Symfony\Component\Console\Output\ConsoleOutput());
}
}
php artisan fixtures:generate App\Entity\User --ids=1,2,3 --output=database/fixtures
// database/seeders/DoctrineFixturesSeeder.php
namespace Database\Seeders;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
class DoctrineFixturesSeeder extends Seeder {
public function run() {
$loader = new Loader();
$loader->loadFromDirectory(__DIR__.'/../fixtures');
$executor = new ORMExecutor(
app('doctrine')->getManager(),
new ORMPurger(app('doctrine')->getManager())
);
$executor->execute($loader->getFixtures());
}
}
php artisan db:seed --class=DoctrineFixturesSeeder
// app/Models/User.php
use Doctrine\ORM\Mapping as ORM;
How can I help you explore Laravel packages today?