Yaffs site version 1.1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / LegacyContainerBuilderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\ContainerBuilder;
16 use Symfony\Component\DependencyInjection\Reference;
17
18 /**
19  * @group legacy
20  */
21 class LegacyContainerBuilderTest extends TestCase
22 {
23     public function testCreateServiceFactoryMethod()
24     {
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');
31     }
32
33     public function testCreateServiceFactoryService()
34     {
35         $builder = new ContainerBuilder();
36         $builder->register('baz_service')->setFactoryService('baz_factory')->setFactoryMethod('getInstance');
37         $builder->register('baz_factory', 'BazClass');
38
39         $this->assertInstanceOf('BazClass', $builder->get('baz_service'));
40     }
41 }