From 3cbfe8ca8f31f9c72a6692f69e278cd685895f70 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 29 Apr 2020 19:55:37 +0200 Subject: [PATCH] Fix CI when testing with Symfony 5.1 --- DependencyInjection/Configuration.php | 26 ++++++++++++++++++- .../AbstractDoctrineExtensionTest.php | 5 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e6e3fd1cb..8c342cc0b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -4,6 +4,7 @@ use Doctrine\ORM\EntityManager; use ReflectionClass; +use Symfony\Component\Config\Definition\BaseNode; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -91,7 +92,7 @@ private function addDbalSection(ArrayNodeDefinition $node) : void ->end() ->children() ->scalarNode('class')->isRequired()->end() - ->booleanNode('commented')->setDeprecated()->end() + ->booleanNode('commented')->setDeprecated(...$this->getCommentedParamDeprecationMsg())->end() ->end() ->end() ->end() @@ -685,4 +686,27 @@ private function getAutoGenerateModes() : array 'values' => $valuesArray, ]; } + + /** + * Returns the correct deprecation param's as an array for setDeprecated. + * + * Symfony/Config v5.1 introduces a deprecation notice when calling + * setDeprecation() with less than 3 args and the getDeprecation method was + * introduced at the same time. By checking if getDeprecation() exists, + * we can determine the correct param count to use when calling setDeprecated. + */ + private function getCommentedParamDeprecationMsg() : array + { + $message = 'The doctrine-bundle type commenting features were removed; the corresponding config parameter was deprecated in 2.0 and will be dropped in 3.0.'; + + if (method_exists(BaseNode::class, 'getDeprecation')) { + return [ + 'doctrine/doctrine-bundle', + '2.0', + $message, + ]; + } + + return [$message]; + } } diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 8c0ddf09e..531633e2a 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -643,8 +643,7 @@ public function testResolveTargetEntity() : void $definition = $container->getDefinition('doctrine.orm.listeners.resolve_target_entity'); $this->assertDICDefinitionMethodCallOnce($definition, 'addResolveTargetEntity', ['Symfony\Component\Security\Core\User\UserInterface', 'MyUserClass', []]); - - $this->assertEquals(['doctrine.event_subscriber' => [[]]], $definition->getTags()); + $this->assertSame([ [] ], $definition->getTags()['doctrine.event_subscriber']); } public function testAttachEntityListeners() : void @@ -655,7 +654,7 @@ public function testAttachEntityListeners() : void $methodCalls = $definition->getMethodCalls(); $this->assertDICDefinitionMethodCallCount($definition, 'addEntityListener', [], 6); - $this->assertEquals(['doctrine.event_listener' => [ ['event' => 'loadClassMetadata'] ] ], $definition->getTags()); + $this->assertSame([ ['event' => 'loadClassMetadata'] ], $definition->getTags()['doctrine.event_subscriber']); $this->assertEquals($methodCalls[0], [ 'addEntityListener',