From 4f80bc1297c0af3c4ee733492ca46c85ce853317 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 | 35 ++++++++++++------- .../DoctrineExtensionTest.php | 9 +++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index c7271f69..cc520c17 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -34,10 +34,12 @@ use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; 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 +491,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(class_exists(AnnotationLoader::class) ? 'doctrine.orm.default_annotation_metadata_driver' : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); @@ -510,9 +512,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( + ! class_exists(AnnotationLoader::class) ? [ + __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 +550,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 = class_exists(AnnotationLoader::class) ? 'doctrine.orm.em1_annotation_metadata_driver' : 'doctrine.orm.em1_attribute_metadata_driver'; $this->assertDICDefinitionMethodCallAt(0, $def1, 'addDriver', [ new Reference($def1Id), @@ -565,14 +572,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 (class_exists(AnnotationLoader::class)) { + $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..08438be5 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -51,6 +51,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory; use Symfony\Component\Messenger\MessageBusInterface; +use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use function array_values; use function class_exists; @@ -842,7 +843,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(class_exists(AnnotationLoader::class) + ? 'doctrine.orm.default_annotation_metadata_driver' + : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); } @@ -925,7 +928,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(class_exists(AnnotationLoader::class) + ? 'doctrine.orm.default_annotation_metadata_driver' + : 'doctrine.orm.default_attribute_metadata_driver'), 'Fixtures\Bundles\AnnotationsBundle\Entity', ]); $this->assertDICDefinitionMethodCallAt(1, $definition, 'addDriver', [