public function ContainerBuilderTest::testCreateServiceFactory in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/dependency-injection/Tests/ContainerBuilderTest.php \Symfony\Component\DependencyInjection\Tests\ContainerBuilderTest::testCreateServiceFactory()
@covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
File
- vendor/
symfony/ dependency-injection/ Tests/ ContainerBuilderTest.php, line 329
Class
Namespace
Symfony\Component\DependencyInjection\TestsCode
public function testCreateServiceFactory() {
$builder = new ContainerBuilder();
$builder
->register('foo', 'Bar\\FooClass')
->setFactory('Bar\\FooClass::getInstance');
$builder
->register('qux', 'Bar\\FooClass')
->setFactory(array(
'Bar\\FooClass',
'getInstance',
));
$builder
->register('bar', 'Bar\\FooClass')
->setFactory(array(
new Definition('Bar\\FooClass'),
'getInstance',
));
$builder
->register('baz', 'Bar\\FooClass')
->setFactory(array(
new Reference('bar'),
'getInstance',
));
$this
->assertTrue($builder
->get('foo')->called, '->createService() calls the factory method to create the service instance');
$this
->assertTrue($builder
->get('qux')->called, '->createService() calls the factory method to create the service instance');
$this
->assertTrue($builder
->get('bar')->called, '->createService() uses anonymous service as factory');
$this
->assertTrue($builder
->get('baz')->called, '->createService() uses another service as factory');
}