Updating Media dependent modules to versions compatible with core Media.
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / ResolveFactoryClassPassTest.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\Compiler;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\ResolveFactoryClassPass;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
17 use Symfony\Component\DependencyInjection\Definition;
18 use Symfony\Component\DependencyInjection\Reference;
19
20 class ResolveFactoryClassPassTest extends TestCase
21 {
22     public function testProcess()
23     {
24         $container = new ContainerBuilder();
25
26         $factory = $container->register('factory', 'Foo\Bar');
27         $factory->setFactory(array(null, 'create'));
28
29         $pass = new ResolveFactoryClassPass();
30         $pass->process($container);
31
32         $this->assertSame(array('Foo\Bar', 'create'), $factory->getFactory());
33     }
34
35     public function testInlinedDefinitionFactoryIsProcessed()
36     {
37         $container = new ContainerBuilder();
38
39         $factory = $container->register('factory');
40         $factory->setFactory(array((new Definition('Baz\Qux'))->setFactory(array(null, 'getInstance')), 'create'));
41
42         $pass = new ResolveFactoryClassPass();
43         $pass->process($container);
44
45         $this->assertSame(array('Baz\Qux', 'getInstance'), $factory->getFactory()[0]->getFactory());
46     }
47
48     public function provideFulfilledFactories()
49     {
50         return array(
51             array(array('Foo\Bar', 'create')),
52             array(array(new Reference('foo'), 'create')),
53             array(array(new Definition('Baz'), 'create')),
54         );
55     }
56
57     /**
58      * @dataProvider provideFulfilledFactories
59      */
60     public function testIgnoresFulfilledFactories($factory)
61     {
62         $container = new ContainerBuilder();
63         $definition = new Definition();
64         $definition->setFactory($factory);
65
66         $container->setDefinition('factory', $definition);
67
68         $pass = new ResolveFactoryClassPass();
69         $pass->process($container);
70
71         $this->assertSame($factory, $container->getDefinition('factory')->getFactory());
72     }
73
74     /**
75      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
76      * @expectedExceptionMessage The "factory" service is defined to be created by a factory, but is missing the factory class. Did you forget to define the factory or service class?
77      */
78     public function testNotAnyClassThrowsException()
79     {
80         $container = new ContainerBuilder();
81
82         $factory = $container->register('factory');
83         $factory->setFactory(array(null, 'create'));
84
85         $pass = new ResolveFactoryClassPass();
86         $pass->process($container);
87     }
88 }