Skip to content

Commit 560f092

Browse files
committed
[DependencyInjection] Exclude current id from non-existent references alternatives
1 parent feae98c commit 560f092

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function getAlternatives(string $id): array
9090
{
9191
$alternatives = [];
9292
foreach ($this->container->getServiceIds() as $knownId) {
93-
if ('' === $knownId || '.' === $knownId[0]) {
93+
if ('' === $knownId || '.' === $knownId[0] || $knownId === $this->currentId) {
9494
continue;
9595
}
9696

Tests/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ public function testProcessThrowsExceptionOnInvalidReferenceWithAlternatives()
124124
$this->process($container);
125125
}
126126

127+
public function testCurrentIdIsExcludedFromAlternatives()
128+
{
129+
$this->expectException(ServiceNotFoundException::class);
130+
$this->expectExceptionMessage('The service "app.my_service" has a dependency on a non-existent service "app.my_service2".');
131+
132+
$container = new ContainerBuilder();
133+
$container
134+
->register('app.my_service', \stdClass::class)
135+
->addArgument(new Reference('app.my_service2'));
136+
137+
$this->process($container);
138+
}
139+
127140
private function process(ContainerBuilder $container)
128141
{
129142
$pass = new CheckExceptionOnInvalidReferenceBehaviorPass();

0 commit comments

Comments
 (0)