From e953daf2429b570828ac9da2eca685062365f104 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 28 Mar 2020 09:54:30 -0400 Subject: [PATCH 1/4] Fixing deprecated Doctrine\Common code in templates --- src/Doctrine/EntityClassGenerator.php | 3 +++ src/Doctrine/EntityRegenerator.php | 3 +++ src/Maker/MakeFixtures.php | 6 +++++- src/Resources/skeleton/doctrine/Fixtures.tpl.php | 2 +- src/Resources/skeleton/doctrine/Repository.tpl.php | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Doctrine/EntityClassGenerator.php b/src/Doctrine/EntityClassGenerator.php index 190f57d80..57757199d 100644 --- a/src/Doctrine/EntityClassGenerator.php +++ b/src/Doctrine/EntityClassGenerator.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\MakerBundle\Doctrine; +use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\MakerBundle\Generator; use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; @@ -52,6 +54,7 @@ public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $ 'entity_class_name' => $entityClassDetails->getShortName(), 'entity_alias' => $entityAlias, 'with_password_upgrade' => $withPasswordUpgrade, + 'doctrine_registry_class' => interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class, ] ); diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index 490938bd3..0569ebf85 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -11,9 +11,11 @@ namespace Symfony\Bundle\MakerBundle\Doctrine; +use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry; use Doctrine\Common\Persistence\Mapping\MappingException as CommonMappingException; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; use Symfony\Bundle\MakerBundle\FileManager; use Symfony\Bundle\MakerBundle\Generator; @@ -235,6 +237,7 @@ private function generateRepository(ClassMetadata $metadata) 'entity_class_name' => $entityClassName, 'entity_alias' => strtolower($entityClassName[0]), 'with_password_upgrade' => false, + 'doctrine_registry_class' => interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class, ] ); diff --git a/src/Maker/MakeFixtures.php b/src/Maker/MakeFixtures.php index d4343cfb3..291eb4db8 100644 --- a/src/Maker/MakeFixtures.php +++ b/src/Maker/MakeFixtures.php @@ -12,7 +12,9 @@ namespace Symfony\Bundle\MakerBundle\Maker; use Doctrine\Bundle\FixturesBundle\Fixture; +use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager; use Doctrine\ORM\Mapping\Column; +use Doctrine\Persistence\ObjectManager; use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; use Symfony\Bundle\MakerBundle\Generator; @@ -51,7 +53,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $generator->generateClass( $fixturesClassNameDetails->getFullName(), 'doctrine/Fixtures.tpl.php', - [] + [ + 'object_manager_class' => interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class, + ] ); $generator->writeChanges(); diff --git a/src/Resources/skeleton/doctrine/Fixtures.tpl.php b/src/Resources/skeleton/doctrine/Fixtures.tpl.php index 9cc4f45de..b0b52e42b 100644 --- a/src/Resources/skeleton/doctrine/Fixtures.tpl.php +++ b/src/Resources/skeleton/doctrine/Fixtures.tpl.php @@ -3,7 +3,7 @@ namespace ; use Doctrine\Bundle\FixturesBundle\Fixture; -use Doctrine\Common\Persistence\ObjectManager; +use ; class extends Fixture { diff --git a/src/Resources/skeleton/doctrine/Repository.tpl.php b/src/Resources/skeleton/doctrine/Repository.tpl.php index 7457915b8..a450c9577 100644 --- a/src/Resources/skeleton/doctrine/Repository.tpl.php +++ b/src/Resources/skeleton/doctrine/Repository.tpl.php @@ -4,7 +4,7 @@ use ; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Common\Persistence\ManagerRegistry; +use ; From 54e356e893df6c6aefe73719309d682265a76883 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 28 Mar 2020 10:09:10 -0400 Subject: [PATCH 2/4] Fixing bad sprintf --- src/Util/YamlSourceManipulator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php index d40be4298..267111a51 100644 --- a/src/Util/YamlSourceManipulator.php +++ b/src/Util/YamlSourceManipulator.php @@ -130,7 +130,7 @@ private function updateData(array $newData) $this->arrayTypeForDepths[$this->depth] = $this->isHash($currentData) ? self::ARRAY_TYPE_HASH : self::ARRAY_TYPE_SEQUENCE; $this->log(sprintf( - 'Changing array type & format via updateData()', + 'Changing array type & format via updateData() (type=%s, format=%s)', $this->arrayTypeForDepths[$this->depth], $this->arrayFormatForDepths[$this->depth] )); From 845fdf0d027075d142dbe3233202775b5b6f8094 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 28 Mar 2020 10:19:20 -0400 Subject: [PATCH 3/4] updating cs --- tests/Maker/MakeMessageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Maker/MakeMessageTest.php b/tests/Maker/MakeMessageTest.php index f331f8b36..898e07236 100644 --- a/tests/Maker/MakeMessageTest.php +++ b/tests/Maker/MakeMessageTest.php @@ -23,11 +23,11 @@ public function getTestDetails() yield 'message_basic' => [MakerTestDetails::createTest( $this->getMakerInstance(MakeMessage::class), [ - 'SendWelcomeEmail' + 'SendWelcomeEmail', ]) ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageBasic') // because there is no version compatible with 7.0 - ->setRequiredPhpVersion(70100) + ->setRequiredPhpVersion(70100), ]; yield 'message_with_transport' => [ @@ -35,7 +35,7 @@ public function getTestDetails() $this->getMakerInstance(MakeMessage::class), [ 'SendWelcomeEmail', - 1 + 1, ] ) ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport') @@ -61,7 +61,7 @@ function (string $output, string $directory) { $this->getMakerInstance(MakeMessage::class), [ 'SendWelcomeEmail', - 0 + 0, ] ) ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport') From befcabc6f49c1f365fd92adc846caadc10646c73 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 28 Mar 2020 10:44:21 -0400 Subject: [PATCH 4/4] Adding a hack to work around a remaining direct deprecation in PHP < 7.3 --- tests/Doctrine/EntityRegeneratorTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Doctrine/EntityRegeneratorTest.php b/tests/Doctrine/EntityRegeneratorTest.php index b24419830..68f094a6a 100644 --- a/tests/Doctrine/EntityRegeneratorTest.php +++ b/tests/Doctrine/EntityRegeneratorTest.php @@ -38,6 +38,17 @@ class EntityRegeneratorTest extends TestCase */ public function testRegenerateEntities(string $expectedDirName, bool $overwrite) { + /* + * Prior to symfony/doctrine-bridge 5.0 (which require + * PHP 7.3), the deprecated Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain + * is used when our test container. This shows up as a *direct* + * deprecation. We're choosing to silence it here, instead of + * ignoring all direct deprecations. + */ + if (\PHP_VERSION_ID < 70300) { + $this->setGroups(['@legacy']); + } + $kernel = new TestEntityRegeneratorKernel('dev', true); $this->doTestRegeneration( __DIR__.'/fixtures/source_project',