bug #17942 Fix bug when using an private aliased factory service (WouterJ)

This PR was squashed before being merged into the 2.3 branch (closes #17942).

Discussion
----------

Fix bug when using an private aliased factory service

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17910, #17915
| License       | MIT
| Doc PR        | -

/cc @xabbuh

Commits
-------

de406c0 Fix bug when using an private aliased factory service
This commit is contained in:
Fabien Potencier 2016-02-28 16:06:54 +01:00
commit 85c4b06211
2 changed files with 23 additions and 1 deletions

View File

@ -131,6 +131,6 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
return;
}
return $currentId === $factoryService ? $newId : $currentId;
return $currentId === $factoryService ? $newId : $factoryService;
}
}

View File

@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitio
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
require_once __DIR__.'/../Fixtures/includes/foo.php';
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
{
public function testProcess()
@ -44,6 +46,26 @@ class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
$this->assertSame('b_alias', $aDefinition->getFactoryService());
}
/**
* @group legacy
*/
public function testPrivateAliasesInFactory()
{
$container = new ContainerBuilder();
$container->register('a', 'FooClass');
$container->register('b', 'FooClass')
->setFactoryService('a')
->setFactoryMethod('getInstance');
$container->register('c', 'stdClass')->setPublic(false);
$container->setAlias('c_alias', 'c');
$this->process($container);
$this->assertInstanceOf('FooClass', $container->get('b'));
}
/**
* @expectedException \InvalidArgumentException
*/