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\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Alias;
16 use Symfony\Component\DependencyInjection\Reference;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
20 * This class tests the integration of the different compiler passes.
22 class IntegrationTest extends TestCase
25 * This tests that dependencies are correctly processed.
27 * We're checking that:
29 * * A is public, B/C are private
33 public function testProcessRemovesAndInlinesRecursively()
35 $container = new ContainerBuilder();
36 $container->setResourceTracking(false);
39 ->register('a', '\stdClass')
40 ->addArgument(new Reference('c'))
44 ->register('b', '\stdClass')
45 ->addArgument(new Reference('c'))
50 ->register('c', '\stdClass')
54 $container->compile();
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'));
63 public function testProcessInlinesReferencesToAliases()
65 $container = new ContainerBuilder();
66 $container->setResourceTracking(false);
69 ->register('a', '\stdClass')
70 ->addArgument(new Reference('b'))
73 $container->setAlias('b', new Alias('c', false));
76 ->register('c', '\stdClass')
80 $container->compile();
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'));
89 public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDefinition()
91 $container = new ContainerBuilder();
92 $container->setResourceTracking(false);
95 ->register('a', '\stdClass')
96 ->addArgument(new Reference('b'))
97 ->addMethodCall('setC', array(new Reference('c')))
101 ->register('b', '\stdClass')
102 ->addArgument(new Reference('c'))
107 ->register('c', '\stdClass')
111 $container->compile();
113 $this->assertTrue($container->hasDefinition('a'));
114 $this->assertFalse($container->hasDefinition('b'));
115 $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');