Skip to content

Commit 85c4b06

Browse files
committed
bug symfony#17942 Fix bug when using an private aliased factory service (WouterJ)
This PR was squashed before being merged into the 2.3 branch (closes symfony#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 | symfony#17910, symfony#17915 | License | MIT | Doc PR | - /cc @xabbuh Commits ------- de406c0 Fix bug when using an private aliased factory service
2 parents 0ca4ec2 + de406c0 commit 85c4b06

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ private function updateFactoryServiceReference($factoryService, $currentId, $new
131131
return;
132132
}
133133

134-
return $currentId === $factoryService ? $newId : $currentId;
134+
return $currentId === $factoryService ? $newId : $factoryService;
135135
}
136136
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Definition;
1717

18+
require_once __DIR__.'/../Fixtures/includes/foo.php';
19+
1820
class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase
1921
{
2022
public function testProcess()
@@ -44,6 +46,26 @@ public function testProcess()
4446
$this->assertSame('b_alias', $aDefinition->getFactoryService());
4547
}
4648

49+
/**
50+
* @group legacy
51+
*/
52+
public function testPrivateAliasesInFactory()
53+
{
54+
$container = new ContainerBuilder();
55+
56+
$container->register('a', 'FooClass');
57+
$container->register('b', 'FooClass')
58+
->setFactoryService('a')
59+
->setFactoryMethod('getInstance');
60+
61+
$container->register('c', 'stdClass')->setPublic(false);
62+
$container->setAlias('c_alias', 'c');
63+
64+
$this->process($container);
65+
66+
$this->assertInstanceOf('FooClass', $container->get('b'));
67+
}
68+
4769
/**
4870
* @expectedException \InvalidArgumentException
4971
*/

0 commit comments

Comments
 (0)