DoctrineFixturesBundle icon indicating copy to clipboard operation
DoctrineFixturesBundle copied to clipboard

Calling a fixtures load inside of a class

Open geoff-maddock opened this issue 4 years ago • 1 comments

If I run a fixtures load command from the command line, it works as expected:

/srv/api # php bin/console doctrine:fixtures:load

 Careful, database "powerdns" will be purged. Do you want to continue? (yes/no) [no]:
 > yes

   > purging database
   > loading App\DataFixtures\AppFixtures

But if I set up and call the load method, no data is loaded:

        $fixture = new AppFixtures();
        $fixture->load($this->entityManager);

Is there a way to manually load fixtures data like this?

geoff-maddock avatar Dec 14 '20 21:12 geoff-maddock

There should be, but the interactive mode is incorrectly handled. I've submitted a fix waiting for review here: https://github.com/doctrine/DoctrineFixturesBundle/pull/338

After this gets pulled, you can call it from another command like this:

$command = $this->getApplication()->find('doctrine:fixtures:load');
$command->run(new ArrayInput(["--no-interaction" => true]), $output);

Or from your controller as in https://symfony.com/doc/current/console/command_in_controller.html

rapliandras avatar Jan 12 '21 14:01 rapliandras