Yaffs site version 1.1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / IntegrationTest.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\Alias;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18
19 /**
20  * This class tests the integration of the different compiler passes.
21  */
22 class IntegrationTest extends TestCase
23 {
24     /**
25      * This tests that dependencies are correctly processed.
26      *
27      * We're checking that:
28      *
29      *   * A is public, B/C are private
30      *   * A -> C
31      *   * B -> C
32      */
33     public function testProcessRemovesAndInlinesRecursively()
34     {
35         $container = new ContainerBuilder();
36         $container->setResourceTracking(false);
37
38         $a = $container
39             ->register('a', '\stdClass')
40             ->addArgument(new Reference('c'))
41         ;
42
43         $b = $container
44             ->register('b', '\stdClass')
45             ->addArgument(new Reference('c'))
46             ->setPublic(false)
47         ;
48
49         $c = $container
50             ->register('c', '\stdClass')
51             ->setPublic(false)
52         ;
53
54         $container->compile();
55
56         $this->assertTrue($container->hasDefinition('a'));
57         $arguments = $a->getArguments();
58         $this->assertSame($c, $arguments[0]);
59         $this->assertFalse($container->hasDefinition('b'));
60         $this->assertFalse($container->hasDefinition('c'));
61     }
62
63     public function testProcessInlinesReferencesToAliases()
64     {
65         $container = new ContainerBuilder();
66         $container->setResourceTracking(false);
67
68         $a = $container
69             ->register('a', '\stdClass')
70             ->addArgument(new Reference('b'))
71         ;
72
73         $container->setAlias('b', new Alias('c', false));
74
75         $c = $container
76             ->register('c', '\stdClass')
77             ->setPublic(false)
78         ;
79
80         $container->compile();
81
82         $this->assertTrue($container->hasDefinition('a'));
83         $arguments = $a->getArguments();
84         $this->assertSame($c, $arguments[0]);
85         $this->assertFalse($container->hasAlias('b'));
86         $this->assertFalse($container->hasDefinition('c'));
87     }
88
89     public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDefinition()
90     {
91         $container = new ContainerBuilder();
92         $container->setResourceTracking(false);
93
94         $container
95             ->register('a', '\stdClass')
96             ->addArgument(new Reference('b'))
97             ->addMethodCall('setC', array(new Reference('c')))
98         ;
99
100         $container
101             ->register('b', '\stdClass')
102             ->addArgument(new Reference('c'))
103             ->setPublic(false)
104         ;
105
106         $container
107             ->register('c', '\stdClass')
108             ->setPublic(false)
109         ;
110
111         $container->compile();
112
113         $this->assertTrue($container->hasDefinition('a'));
114         $this->assertFalse($container->hasDefinition('b'));
115         $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
116     }
117 }