Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1550649

Browse files
committed
[DependencyInjection] Fix FactoryReturnTypePass position in PassConfig
1 parent 4eeb1f0 commit 1550649

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public function __construct()
4444
new ResolveDefinitionTemplatesPass(),
4545
new DecoratorServicePass(),
4646
new ResolveParameterPlaceHoldersPass(),
47+
new FactoryReturnTypePass(),
4748
new CheckDefinitionValidityPass(),
4849
new ResolveReferencesToAliasesPass(),
4950
new ResolveInvalidReferencesPass(),
50-
new FactoryReturnTypePass(),
5151
new AutowirePass(),
5252
new AnalyzeServiceReferencesPass(true),
5353
new CheckCircularReferencesPass(),

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public function testProcess()
3030
$factory = $container->register('factory');
3131
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
3232

33+
$container->setAlias('alias_factory', 'factory');
34+
3335
$foo = $container->register('foo');
34-
$foo->setFactory(array(new Reference('factory'), 'create'));
36+
$foo->setFactory(array(new Reference('alias_factory'), 'create'));
3537

3638
$bar = $container->register('bar', __CLASS__);
3739
$bar->setFactory(array(new Reference('factory'), 'create'));
@@ -100,4 +102,22 @@ public function testCircularReference()
100102
$this->assertNull($factory->getClass());
101103
$this->assertNull($factory2->getClass());
102104
}
105+
106+
public function testCompile()
107+
{
108+
$container = new ContainerBuilder();
109+
110+
$factory = $container->register('factory');
111+
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
112+
113+
try {
114+
$container->compile();
115+
} catch (\RuntimeException $e) {
116+
if (method_exists(\ReflectionMethod::class, 'getReturnType')) {
117+
$this->fail('The FactoryReturnTypePass should set the class to service "factory".');
118+
} else {
119+
$this->assertEquals('Please add the class to service "factory" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $e->getMessage());
120+
}
121+
}
122+
}
103123
}

0 commit comments

Comments
 (0)