Skip to content

Commit

Permalink
bug #20263 [DependencyInjection] Fix FactoryReturnTypePass position i…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
fabpot committed Oct 21, 2016
2 parents 0471e7b + dfb5cc3 commit 2a14cf2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -44,10 +44,10 @@ public function __construct()
new ResolveDefinitionTemplatesPass(),
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(),
new FactoryReturnTypePass(),
new CheckDefinitionValidityPass(),
new ResolveReferencesToAliasesPass(),
new ResolveInvalidReferencesPass(),
new FactoryReturnTypePass(),
new AutowirePass(),
new AnalyzeServiceReferencesPass(true),
new CheckCircularReferencesPass(),
Expand Down
Expand Up @@ -30,8 +30,10 @@ public function testProcess()
$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'));
Expand Down Expand Up @@ -100,4 +102,20 @@ public function testCircularReference()
$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());
}
}

0 comments on commit 2a14cf2

Please sign in to comment.