diff --git a/Command/LoadDataFixturesDoctrineCommand.php b/Command/LoadDataFixturesDoctrineCommand.php index 18fc371d..d4bea034 100644 --- a/Command/LoadDataFixturesDoctrineCommand.php +++ b/Command/LoadDataFixturesDoctrineCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Style\SymfonyStyle; use const E_USER_DEPRECATED; use function implode; +use function method_exists; use function sprintf; use function trigger_error; @@ -38,7 +39,8 @@ public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegis ), E_USER_DEPRECATED); } - parent::__construct($doctrine); + // @todo The method_exists call can be removed once the DoctrineBundle dependency has been bumped to at least 1.10 + parent::__construct(method_exists($this, 'getDoctrine') ? $doctrine : null); $this->fixturesLoader = $fixturesLoader; } @@ -83,9 +85,15 @@ protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - /** @var ManagerRegistry $doctrine */ - $doctrine = $this->getContainer()->get('doctrine'); - $em = $doctrine->getManager($input->getOption('em')); + // @todo The method_exists call can be removed once the DoctrineBundle dependency has been bumped to at least 1.10 + if (method_exists($this, 'getDotrine')) { + $doctrine = $this->getDoctrine(); + } else { + /** @var ManagerRegistry $doctrine */ + $doctrine = $this->getContainer()->get('doctrine'); + } + + $em = $doctrine->getManager($input->getOption('em')); if (! $input->getOption('append')) { if (! $ui->confirm(sprintf('Careful, database "%s" will be purged. Do you want to continue?', $em->getConnection()->getDatabase()), ! $input->isInteractive())) { diff --git a/Tests/Command/LoadDataFixturesDoctrineCommandTest.php b/Tests/Command/LoadDataFixturesDoctrineCommandTest.php new file mode 100644 index 00000000..d5b066c4 --- /dev/null +++ b/Tests/Command/LoadDataFixturesDoctrineCommandTest.php @@ -0,0 +1,36 @@ +createMock(ManagerRegistry::class); + $loader = new SymfonyFixturesLoader(new Container()); + + new LoadDataFixturesDoctrineCommand($loader, $registry); + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 96387152..716bd481 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -17,4 +17,8 @@ + + + +