8000 bug #39151 [DependencyInjection] Fixed incorrect report for private s… · symfony/symfony@fbd67c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit fbd67c8

Browse files
committed
bug #39151 [DependencyInjection] Fixed incorrect report for private services if required service does not exist (Islam93)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Fixed incorrect report for private services if required service does not exist …does not exist | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #29359 | License | MIT | Doc PR | no looks like `CheckExceptionOnInvalidReferenceBehaviorPass` can be moved to `beforeRemovingPasses` section without any consequences. this solves the problem and all tests still pass Commits ------- 39bd05c [DependencyInjection] Fixed incorrect report for private services if required service does not exist
2 parents 7882c4a + 39bd05c commit fbd67c8

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ public function __construct()
8282
new ReplaceAliasByActualDefinitionPass(),
8383
new RemoveAbstractDefinitionsPass(),
8484
new RemoveUnusedDefinitionsPass(),
85+
new AnalyzeServiceReferencesPass(),
86+
new CheckExceptionOnInvalidReferenceBehaviorPass(),
8587
new InlineServiceDefinitionsPass(new AnalyzeServiceReferencesPass()),
8688
new AnalyzeServiceReferencesPass(),
8789
new DefinitionErrorExceptionPass(),
8890
]];
8991

9092
$this->afterRemovingPasses = [[
91-
new CheckExceptionOnInvalidReferenceBehaviorPass(),
9293
new ResolveHotPathPass(),
9394
]];
9495
}

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,47 @@ public function testNoClassFromNsSeparatorId()
13161316
$container->compile();
13171317
}
13181318

1319+
public function testGetThrownServiceNotFoundExceptionWithCorrectServiceId()
1320+
{
1321+
$this->expectException(ServiceNotFoundException::class);
1322+
$this->expectExceptionMessage('The service "child_service" has a dependency on a non-existent service "non_existent_service".');
1323+
1324+
$container = new ContainerBuilder();
1325+
$container->register('child_service', \stdClass::class)
1326+
->setPublic(false)
1327+
->addArgument([
1328+
'non_existent' => new Reference('non_existent_service'),
1329+
])
1330+
;
1331+
$container->register('parent_service', \stdClass::class)
1332+
->setPublic(true)
1333+
->addArgument([
1334+
'child_service' => new Reference('child_service'),
1335+
])
1336+
;
1337+
1338+
$container->compile();
1339+
}
1340+
1341+
public function testUnusedServiceRemovedByPassAndServiceNotFoundExceptionWasNotThrown()
1342+
{
1343+
$container = new ContainerBuilder();
1344+
$container->register('service', \stdClass::class)
1345+
->setPublic(false)
1346+
->addArgument([
1347+
'non_existent_service' => new Reference('non_existent_service'),
1348+
])
1349+
;
1350+
1351+
try {
1352+
$container->compile();
1353+
} catch (ServiceNotFoundException $e) {
1354+
$this->fail('Should not be thrown');
1355+
}
1356+
1357+
$this->addToAssertionCount(1);
1358+
}
1359+
13191360
public function testServiceLocator()
13201361
{
13211362
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)
0