From 31d101b868255820edcce43db2a538e9d81c5cac Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Mon, 27 May 2019 17:40:57 -0400 Subject: [PATCH] Fix deprecation on load fixtures command --- Command/LoadDataFixturesDoctrineCommand.php | 14 ++++++++++++-- Resources/config/services.xml | 1 + Tests/IntegrationTest.php | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Command/LoadDataFixturesDoctrineCommand.php b/Command/LoadDataFixturesDoctrineCommand.php index 2aa95c6f..18fc371d 100644 --- a/Command/LoadDataFixturesDoctrineCommand.php +++ b/Command/LoadDataFixturesDoctrineCommand.php @@ -15,8 +15,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use const E_USER_DEPRECATED; use function implode; use function sprintf; +use function trigger_error; /** * Load data fixtures from bundles. @@ -26,9 +28,17 @@ class LoadDataFixturesDoctrineCommand extends DoctrineCommand /** @var SymfonyFixturesLoader */ private $fixturesLoader; - public function __construct(SymfonyFixturesLoader $fixturesLoader) + public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegistry $doctrine = null) { - parent::__construct(); + if ($doctrine === null) { + @trigger_error(sprintf( + 'The "%s" constructor expects a "%s" instance as second argument, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.', + static::class, + ManagerRegistry::class + ), E_USER_DEPRECATED); + } + + parent::__construct($doctrine); $this->fixturesLoader = $fixturesLoader; } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 6a1b439e..b10ce24b 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -7,6 +7,7 @@ + diff --git a/Tests/IntegrationTest.php b/Tests/IntegrationTest.php index 68698540..6959e2e0 100644 --- a/Tests/IntegrationTest.php +++ b/Tests/IntegrationTest.php @@ -12,6 +12,7 @@ use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures; use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\FooBundle; use Doctrine\Common\DataFixtures\Loader; +use Doctrine\Common\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; @@ -348,6 +349,7 @@ protected function configureRoutes(RouteCollectionBuilder $routes) : void protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) : void { $c->setParameter('kernel.secret', 'foo'); + $c->register('doctrine', ManagerRegistry::class); $callback = $this->servicesCallback; $callback($c); }