Skip to content

[DependencyInjection] Fix FactoryReturnTypePass position in PassConfig #20263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test will not fail if no RuntimeException is thrown, and there is no assertion in this case


$container->compile();

$this->assertEquals(FactoryDummy::class, $container->getDefinition('factory')->getClass());
}
}