4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
21 class LegacyContainerBuilderTest extends TestCase
23 public function testCreateServiceFactoryMethod()
25 $builder = new ContainerBuilder();
26 $builder->register('bar', 'stdClass');
27 $builder->register('foo1', 'Bar\FooClass')->setFactoryClass('Bar\FooClass')->setFactoryMethod('getInstance')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
28 $builder->setParameter('value', 'bar');
29 $this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
30 $this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
33 public function testCreateServiceFactoryService()
35 $builder = new ContainerBuilder();
36 $builder->register('baz_service')->setFactoryService('baz_factory')->setFactoryMethod('getInstance');
37 $builder->register('baz_factory', 'BazClass');
39 $this->assertInstanceOf('BazClass', $builder->get('baz_service'));