From 4452bb29546ac73b706e29426674c9512b65885d Mon Sep 17 00:00:00 2001 From: David Maicher Date: Sun, 22 Oct 2023 11:42:52 +0200 Subject: [PATCH] fix tests with Symfony 7 due to Annotation support removal --- .../AbstractDoctrineExtensionTest.php | 34 ++++++++++++------- .../DoctrineExtensionTest.php | 8 +++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index c7271f69..5a816dfc 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -38,6 +38,7 @@ use function array_filter; use function array_intersect_key; use function array_keys; +use function array_merge; use function array_values; use function assert; use function class_exists; @@ -489,7 +490,7 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', [ - new Reference('doctrine.orm.default_annotation_metadata_driver'), + new Reference($container->has('annotations.reader') ? 'doctrine.orm.default_annotation_metadata_driver' : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); @@ -510,9 +511,14 @@ public function testSingleEntityManagerMultipleMappingBundleDefinitions(): void $attrDef = $container->getDefinition('doctrine.orm.default_attribute_metadata_driver'); $this->assertDICConstructorArguments($attrDef, [ - [ - __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity', - ], + array_merge( + ! $container->has('annotations.reader') ? [ + __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity', + ] : [], + [ + __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AttributesBundle' . DIRECTORY_SEPARATOR . 'Entity', + ] + ), false, ]); @@ -543,7 +549,7 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void $def1 = $container->getDefinition('doctrine.orm.em1_metadata_driver'); $def2 = $container->getDefinition('doctrine.orm.em2_metadata_driver'); - $def1Id = 'doctrine.orm.em1_annotation_metadata_driver'; + $def1Id = $container->has('annotations.reader') ? 'doctrine.orm.em1_annotation_metadata_driver' : 'doctrine.orm.em1_attribute_metadata_driver'; $this->assertDICDefinitionMethodCallAt(0, $def1, 'addDriver', [ new Reference($def1Id), @@ -565,14 +571,16 @@ public function testMultipleEntityManagersMappingBundleDefinitions(): void 'Fixtures\Bundles\XmlBundle', ]); - $annDef = $container->getDefinition($def1Id); - $this->assertDICConstructorArguments($annDef, [ - new Reference('doctrine.orm.metadata.annotation_reader'), - [ - __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity', - ], - false, - ]); + if ($container->has('annotations.reader')) { + $annDef = $container->getDefinition($def1Id); + $this->assertDICConstructorArguments($annDef, [ + new Reference('doctrine.orm.metadata.annotation_reader'), + [ + __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'Bundles' . DIRECTORY_SEPARATOR . 'AnnotationsBundle' . DIRECTORY_SEPARATOR . 'Entity', + ], + false, + ]); + } $ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver'); $this->assertDICConstructorArguments($ymlDef, [ diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index 9b64c5b9..f708c55b 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -842,7 +842,9 @@ public function testAnnotationsBundleMappingDetection(): void $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', [ - new Reference('doctrine.orm.default_annotation_metadata_driver'), + new Reference($container->has('annotations.reader') + ? 'doctrine.orm.default_annotation_metadata_driver' + : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); } @@ -925,7 +927,9 @@ public function testOrmMergeConfigs(): void $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallAt(0, $definition, 'addDriver', [ - new Reference('doctrine.orm.default_annotation_metadata_driver'), + new Reference($container->has('annotations.reader') + ? 'doctrine.orm.default_annotation_metadata_driver' + : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); $this->assertDICDefinitionMethodCallAt(1, $definition, 'addDriver', [