bug #20263 [DependencyInjection] Fix FactoryReturnTypePass position in PassConfig (hason)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[DependencyInjection] Fix FactoryReturnTypePass position in PassConfig

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

Commits
-------

dfb5cc3 [DependencyInjection] Fix FactoryReturnTypePass position in PassConfig
This commit is contained in:
Fabien Potencier 2016-10-21 14:26:55 -07:00
commit 2a14cf224d
2 changed files with 20 additions and 2 deletions

View File

@ -44,10 +44,10 @@ class PassConfig
new ResolveDefinitionTemplatesPass(),
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(),
new FactoryReturnTypePass(),
new CheckDefinitionValidityPass(),
new ResolveReferencesToAliasesPass(),
new ResolveInvalidReferencesPass(),
new FactoryReturnTypePass(),
new AutowirePass(),
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),

View File

@ -30,8 +30,10 @@ class FactoryReturnTypePassTest extends \PHPUnit_Framework_TestCase
$factory = $container->register('factory');
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
$container->setAlias('alias_factory', 'factory');
$foo = $container->register('foo');
$foo->setFactory(array(new Reference('factory'), 'create'));
$foo->setFactory(array(new Reference('alias_factory'), 'create'));
$bar = $container->register('bar', __CLASS__);
$bar->setFactory(array(new Reference('factory'), 'create'));
@ -100,4 +102,20 @@ class FactoryReturnTypePassTest extends \PHPUnit_Framework_TestCase
$this->assertNull($factory->getClass());
$this->assertNull($factory2->getClass());
}
public function testCompile()
{
$container = new ContainerBuilder();
$factory = $container->register('factory');
$factory->setFactory(array(FactoryDummy::class, 'createFactory'));
if (!method_exists(\ReflectionMethod::class, 'getReturnType')) {
$this->setExpectedException(\RuntimeException::class, '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.');
}
$container->compile();
$this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass());
}
}