Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 534c3fa

Browse filesBrowse files
[FrameworkBundle] Fix setting decorated services during tests
1 parent 5b66f26 commit 534c3fa
Copy full SHA for 534c3fa

File tree

6 files changed

+25
-2
lines changed
Filter options

6 files changed

+25
-2
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function process(ContainerBuilder $container)
4141
if ($id !== $target) {
4242
$renamedIds[$id] = $target;
4343
}
44+
if ($inner = $definitions[$target]->getTag('container.decorator')[0]['inner'] ?? null) {
45+
$renamedIds[$id] = $inner;
46+
}
4447
} else {
4548
unset($privateServices[$id]);
4649
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/PrivateService.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/TestServiceContainer/PrivateService.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
class PrivateService
1515
{
16+
public $inner;
1617
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/TestServiceContainerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/TestServiceContainerTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public function testThatPrivateServicesAreAvailableIfTestConfigIsEnabled()
4040
$this->assertFalse(static::getContainer()->has(UnusedPrivateService::class));
4141
}
4242

43+
public function testSetDecoratedService()
44+
{
45+
static::bootKernel(['test_case' => 'TestServiceContainer']);
46+
47+
$container = static::getContainer();
48+
49+
$service = new PrivateService();
50+
$container->set(PrivateService::class, $service);
51+
$this->assertSame($service, $container->get(PrivateService::class)->inner);
52+
}
53+
4354
/**
4455
* @doesNotPerformAssertions
4556
*/

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/services.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/TestServiceContainer/services.yml
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ services:
1313
arguments:
1414
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService'
1515
- '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService'
16+
17+
decorator:
18+
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService
19+
decorates: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService
20+
properties:
21+
inner: '@.inner'

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ext-xml": "*",
2222
"symfony/cache": "^5.4|^6.0",
2323
"symfony/config": "^6.1",
24-
"symfony/dependency-injection": "^6.3",
24+
"symfony/dependency-injection": "^6.3.1",
2525
"symfony/deprecation-contracts": "^2.5|^3",
2626
"symfony/error-handler": "^6.1",
2727
"symfony/event-dispatcher": "^5.4|^6.0",

‎src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function process(ContainerBuilder $container)
4242
$definitions->insert([$id, $definition], [$decorated[2], --$order]);
4343
}
4444
$decoratingDefinitions = [];
45+
$decoratedIds = [];
4546

4647
$tagsToKeep = $container->hasParameter('container.behavior_describing_tags')
4748
? $container->getParameter('container.behavior_describing_tags')
@@ -58,6 +59,7 @@ public function process(ContainerBuilder $container)
5859
$renamedId = $id.'.inner';
5960
}
6061

62+
$decoratedIds[$inner] ??= $renamedId;
6163
$this->currentId = $renamedId;
6264
$this->processValue($definition);
6365

@@ -114,7 +116,7 @@ public function process(ContainerBuilder $container)
114116
}
115117

116118
foreach ($decoratingDefinitions as $inner => $definition) {
117-
$definition->addTag('container.decorator', ['id' => $inner]);
119+
$definition->addTag('container.decorator', ['id' => $inner, 'inner' => $decoratedIds[$inner]]);
118120
}
119121
}
120122

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.