From 25a718efec43c6aa5a3188467897bcb3022e735b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Fr=C3=A9zet?= Date: Mon, 21 Nov 2022 12:36:25 +0100 Subject: [PATCH] fix: fix a missing service definition in test environment --- .../DeprecateMercurePublisherPass.php | 8 ++++--- .../DeprecateMercurePublisherPassTest.php | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPass.php b/src/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPass.php index b2e426b2f23..aa55d7b9833 100644 --- a/src/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPass.php +++ b/src/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPass.php @@ -27,9 +27,11 @@ final class DeprecateMercurePublisherPass implements CompilerPassInterface { public function process(ContainerBuilder $container) { - $container - ->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish') - ->setDeprecated(...$this->buildDeprecationArgs('2.6', 'Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.')); + if ($container->hasDefinition('api_platform.doctrine.listener.mercure.publish')) { + $container + ->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish') + ->setDeprecated(...$this->buildDeprecationArgs('2.6', 'Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.')); + } } private function buildDeprecationArgs(string $version, string $message): array diff --git a/tests/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPassTest.php b/tests/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPassTest.php index 791bcaebadc..6ef8c6f7be1 100644 --- a/tests/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPassTest.php +++ b/tests/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPassTest.php @@ -25,7 +25,7 @@ final class DeprecateMercurePublisherPassTest extends TestCase { use ProphecyTrait; - public function testProcess() + public function testProcess(): void { $deprecateMercurePublisherPass = new DeprecateMercurePublisherPass(); @@ -34,6 +34,10 @@ public function testProcess() $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); $aliasProphecy = $this->prophesize(Alias::class); + $containerBuilderProphecy + ->hasDefinition('api_platform.doctrine.listener.mercure.publish') + ->willReturn(true); + $containerBuilderProphecy ->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish') ->willReturn($aliasProphecy->reveal()) @@ -50,4 +54,20 @@ public function testProcess() $deprecateMercurePublisherPass->process($containerBuilderProphecy->reveal()); } + + public function testProcessWithoutDefinition(): void + { + $deprecateMercurePublisherPass = new DeprecateMercurePublisherPass(); + $containerBuilderProphecy = $this->prophesize(ContainerBuilder::class); + + $containerBuilderProphecy + ->hasDefinition('api_platform.doctrine.listener.mercure.publish') + ->willReturn(false); + + $containerBuilderProphecy + ->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish') + ->shouldNotBeCalled(); + + $deprecateMercurePublisherPass->process($containerBuilderProphecy->reveal()); + } }