Skip to content

Commit 3939857

Browse files
authored
fix: fix a missing service definition in test environment (#5206)
1 parent 096ac11 commit 3939857

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPass.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ final class DeprecateMercurePublisherPass implements CompilerPassInterface
2727
{
2828
public function process(ContainerBuilder $container)
2929
{
30-
$container
31-
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
32-
->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.'));
30+
if ($container->hasDefinition('api_platform.doctrine.listener.mercure.publish')) {
31+
$container
32+
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
33+
->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.'));
34+
}
3335
}
3436

3537
private function buildDeprecationArgs(string $version, string $message): array

tests/Symfony/Bundle/DependencyInjection/Compiler/DeprecateMercurePublisherPassTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class DeprecateMercurePublisherPassTest extends TestCase
2525
{
2626
use ProphecyTrait;
2727

28-
public function testProcess()
28+
public function testProcess(): void
2929
{
3030
$deprecateMercurePublisherPass = new DeprecateMercurePublisherPass();
3131

@@ -34,6 +34,10 @@ public function testProcess()
3434
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
3535
$aliasProphecy = $this->prophesize(Alias::class);
3636

37+
$containerBuilderProphecy
38+
->hasDefinition('api_platform.doctrine.listener.mercure.publish')
39+
->willReturn(true);
40+
3741
$containerBuilderProphecy
3842
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
3943
->willReturn($aliasProphecy->reveal())
@@ -50,4 +54,20 @@ public function testProcess()
5054

5155
$deprecateMercurePublisherPass->process($containerBuilderProphecy->reveal());
5256
}
57+
58+
public function testProcessWithoutDefinition(): void
59+
{
60+
$deprecateMercurePublisherPass = new DeprecateMercurePublisherPass();
61+
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
62+
63+
$containerBuilderProphecy
64+
->hasDefinition('api_platform.doctrine.listener.mercure.publish')
65+
->willReturn(false);
66+
67+
$containerBuilderProphecy
68+
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
69+
->shouldNotBeCalled();
70+
71+
$deprecateMercurePublisherPass->process($containerBuilderProphecy->reveal());
72+
}
5373
}

0 commit comments

Comments
 (0)