From 3f29412528df3b9d9a9337d2bf63a1bc0b24aa05 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 12 Jun 2019 09:11:53 +0200 Subject: [PATCH 1/3] Add test to instantiate Loader with ManagerRegistry --- .../LoadDataFixturesDoctrineCommandTest.php | 36 +++++++++++++++++++ phpunit.xml.dist | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 Tests/Command/LoadDataFixturesDoctrineCommandTest.php 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 @@ + + + + From 5720cdedebfcd5822d656ca7259ee59ff2c2a122 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 12 Jun 2019 11:46:24 +0200 Subject: [PATCH 2/3] Don't pass wrong object to legacy constructors --- Command/LoadDataFixturesDoctrineCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Command/LoadDataFixturesDoctrineCommand.php b/Command/LoadDataFixturesDoctrineCommand.php index 18fc371d..b62e734a 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; } From c10424a62df875f5eac7c4896c0eb7a0cb379152 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 12 Jun 2019 11:49:02 +0200 Subject: [PATCH 3/3] Remove calls to deprecated method where possible --- Command/LoadDataFixturesDoctrineCommand.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Command/LoadDataFixturesDoctrineCommand.php b/Command/LoadDataFixturesDoctrineCommand.php index b62e734a..d4bea034 100644 --- a/Command/LoadDataFixturesDoctrineCommand.php +++ b/Command/LoadDataFixturesDoctrineCommand.php @@ -85,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())) {