Skip to content

Commit 422430e

Browse files
committed
bug #16926 [DependencyInjection] fixed definition loosing property shared when decorated by a parent definition (wahler)
This PR was squashed before being merged into the 2.8 branch (closes #16926). Discussion ---------- [DependencyInjection] fixed definition loosing property shared when decorated by a parent definition | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | While upgrading my applications from 2.7 and 2.8 I found out that the attribute "shared" gets lost when a parent is configured. I wrote a Test to confirm my assumption and added a bugfix Commits ------- d3a4a77 [DependencyInjection] fixed definition loosing property shared when decorated by a parent definition
2 parents f176156 + d3a4a77 commit 422430e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
211211
// these attributes are always taken from the child
212212
$def->setAbstract($definition->isAbstract());
213213
$def->setScope($definition->getScope(false), false);
214+
$def->setShared($definition->isShared());
214215
$def->setTags($definition->getTags());
215216

216217
return $def;

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ public function testProcessDoesNotCopyScope()
101101
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
102102
}
103103

104+
public function testProcessDoesNotCopyShared()
105+
{
106+
$container = new ContainerBuilder();
107+
108+
$container
109+
->register('parent')
110+
->setShared(false)
111+
;
112+
113+
$container
114+
->setDefinition('child', new DefinitionDecorator('parent'))
115+
;
116+
117+
$this->process($container);
118+
119+
$def = $container->getDefinition('child');
120+
$this->assertTrue($def->isShared());
121+
}
122+
104123
public function testProcessDoesNotCopyTags()
105124
{
106125
$container = new ContainerBuilder();
@@ -139,6 +158,25 @@ public function testProcessDoesNotCopyDecoratedService()
139158
$this->assertNull($def->getDecoratedService());
140159
}
141160

161+
public function testProcessDoesNotDropShared()
162+
{
163+
$container = new ContainerBuilder();
164+
165+
$container
166+
->register('parent')
167+
;
168+
169+
$container
170+
->setDefinition('child', new DefinitionDecorator('parent'))
171+
->setShared(false)
172+
;
173+
174+
$this->process($container);
175+
176+
$def = $container->getDefinition('child');
177+
$this->assertFalse($def->isShared());
178+
}
179+
142180
public function testProcessHandlesMultipleInheritance()
143181
{
144182
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)