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
This commit is contained in:
commit
422430e282
@ -211,6 +211,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
|||||||
// these attributes are always taken from the child
|
// these attributes are always taken from the child
|
||||||
$def->setAbstract($definition->isAbstract());
|
$def->setAbstract($definition->isAbstract());
|
||||||
$def->setScope($definition->getScope(false), false);
|
$def->setScope($definition->getScope(false), false);
|
||||||
|
$def->setShared($definition->isShared());
|
||||||
$def->setTags($definition->getTags());
|
$def->setTags($definition->getTags());
|
||||||
|
|
||||||
return $def;
|
return $def;
|
||||||
|
@ -101,6 +101,25 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
|
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessDoesNotCopyShared()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container
|
||||||
|
->register('parent')
|
||||||
|
->setShared(false)
|
||||||
|
;
|
||||||
|
|
||||||
|
$container
|
||||||
|
->setDefinition('child', new DefinitionDecorator('parent'))
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->process($container);
|
||||||
|
|
||||||
|
$def = $container->getDefinition('child');
|
||||||
|
$this->assertTrue($def->isShared());
|
||||||
|
}
|
||||||
|
|
||||||
public function testProcessDoesNotCopyTags()
|
public function testProcessDoesNotCopyTags()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
@ -139,6 +158,25 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNull($def->getDecoratedService());
|
$this->assertNull($def->getDecoratedService());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessDoesNotDropShared()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$container
|
||||||
|
->register('parent')
|
||||||
|
;
|
||||||
|
|
||||||
|
$container
|
||||||
|
->setDefinition('child', new DefinitionDecorator('parent'))
|
||||||
|
->setShared(false)
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->process($container);
|
||||||
|
|
||||||
|
$def = $container->getDefinition('child');
|
||||||
|
$this->assertFalse($def->isShared());
|
||||||
|
}
|
||||||
|
|
||||||
public function testProcessHandlesMultipleInheritance()
|
public function testProcessHandlesMultipleInheritance()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
Reference in New Issue
Block a user