Skip to content

Commit 3585a2f

Browse files
committed
bug #570 Fixing deprecated Doctrine\Common code in templates (weaverryan)
This PR was squashed before being merged into the 1.0-dev branch (closes #570). Discussion ---------- Fixing deprecated Doctrine\Common code in templates Fixes #570 #560, #524, #528, #519 #570 Commits ------- befcabc Adding a hack to work around a remaining direct deprecation in PHP < 7.3 845fdf0 updating cs 54e356e Fixing bad sprintf e953daf Fixing deprecated Doctrine\Common code in templates
2 parents f404885 + befcabc commit 3585a2f

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

src/Doctrine/EntityClassGenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Persistence\ManagerRegistry;
1416
use Symfony\Bundle\MakerBundle\Generator;
1517
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1618

@@ -52,6 +54,7 @@ public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $
5254
'entity_class_name' => $entityClassDetails->getShortName(),
5355
'entity_alias' => $entityAlias,
5456
'with_password_upgrade' => $withPasswordUpgrade,
57+
'doctrine_registry_class' => interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class,
5558
]
5659
);
5760

src/Doctrine/EntityRegenerator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
1415
use Doctrine\Common\Persistence\Mapping\MappingException as CommonMappingException;
1516
use Doctrine\ORM\Mapping\ClassMetadata;
1617
use Doctrine\ORM\Mapping\MappingException;
18+
use Doctrine\Persistence\ManagerRegistry;
1719
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
1820
use Symfony\Bundle\MakerBundle\FileManager;
1921
use Symfony\Bundle\MakerBundle\Generator;
@@ -235,6 +237,7 @@ private function generateRepository(ClassMetadata $metadata)
235237
'entity_class_name' => $entityClassName,
236238
'entity_alias' => strtolower($entityClassName[0]),
237239
'with_password_upgrade' => false,
240+
'doctrine_registry_class' => interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class,
238241
]
239242
);
240243

src/Maker/MakeFixtures.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
use Doctrine\Bundle\FixturesBundle\Fixture;
15+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
1516
use Doctrine\ORM\Mapping\Column;
17+
use Doctrine\Persistence\ObjectManager;
1618
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1719
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1820
use Symfony\Bundle\MakerBundle\Generator;
@@ -51,7 +53,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5153
$generator->generateClass(
5254
$fixturesClassNameDetails->getFullName(),
5355
'doctrine/Fixtures.tpl.php',
54-
[]
56+
[
57+
'object_manager_class' => interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class,
58+
]
5559
);
5660

5761
$generator->writeChanges();

src/Resources/skeleton/doctrine/Fixtures.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace <?= $namespace; ?>;
44

55
use Doctrine\Bundle\FixturesBundle\Fixture;
6-
use Doctrine\Common\Persistence\ObjectManager;
6+
use <?= $object_manager_class; ?>;
77

88
class <?= $class_name ?> extends Fixture
99
{

src/Resources/skeleton/doctrine/Repository.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use <?= $entity_full_class_name; ?>;
66
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7-
use Doctrine\Common\Persistence\ManagerRegistry;
7+
use <?= $doctrine_registry_class; ?>;
88
<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\Exception\UnsupportedUserException;\n" : '' ?>
99
<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;\n" : '' ?>
1010
<?= $with_password_upgrade ? "use Symfony\Component\Security\Core\User\UserInterface;\n" : '' ?>

src/Util/YamlSourceManipulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private function updateData(array $newData)
130130
$this->arrayTypeForDepths[$this->depth] = $this->isHash($currentData) ? self::ARRAY_TYPE_HASH : self::ARRAY_TYPE_SEQUENCE;
131131

132132
$this->log(sprintf(
133-
'Changing array type & format via updateData()',
133+
'Changing array type & format via updateData() (type=%s, format=%s)',
134134
$this->arrayTypeForDepths[$this->depth],
135135
$this->arrayFormatForDepths[$this->depth]
136136
));

tests/Doctrine/EntityRegeneratorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ class EntityRegeneratorTest extends TestCase
3838
*/
3939
public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
4040
{
41+
/*
42+
* Prior to symfony/doctrine-bridge 5.0 (which require
43+
* PHP 7.3), the deprecated Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
44+
* is used when our test container. This shows up as a *direct*
45+
* deprecation. We're choosing to silence it here, instead of
46+
* ignoring all direct deprecations.
47+
*/
48+
if (\PHP_VERSION_ID < 70300) {
49+
$this->setGroups(['@legacy']);
50+
}
51+
4152
$kernel = new TestEntityRegeneratorKernel('dev', true);
4253
$this->doTestRegeneration(
4354
__DIR__.'/fixtures/source_project',

tests/Maker/MakeMessageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ public function getTestDetails()
2323
yield 'message_basic' => [MakerTestDetails::createTest(
2424
$this->getMakerInstance(MakeMessage::class),
2525
[
26-
'SendWelcomeEmail'
26+
'SendWelcomeEmail',
2727
])
2828
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageBasic')
2929
// because there is no version compatible with 7.0
30-
->setRequiredPhpVersion(70100)
30+
->setRequiredPhpVersion(70100),
3131
];
3232

3333
yield 'message_with_transport' => [
3434
MakerTestDetails::createTest(
3535
$this->getMakerInstance(MakeMessage::class),
3636
[
3737
'SendWelcomeEmail',
38-
1
38+
1,
3939
]
4040
)
4141
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport')
@@ -61,7 +61,7 @@ function (string $output, string $directory) {
6161
$this->getMakerInstance(MakeMessage::class),
6262
[
6363
'SendWelcomeEmail',
64-
0
64+
0,
6565
]
6666
)
6767
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport')

0 commit comments

Comments
 (0)