810fbe48a573f59f327f26c05607d86549080504
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / ExtensionCompilerPassTest.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\CompilerPassInterface;
16 use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
17 use Symfony\Component\DependencyInjection\ContainerBuilder;
18 use Symfony\Component\DependencyInjection\Extension\Extension;
19
20 /**
21  * @author Wouter J <wouter@wouterj.nl>
22  */
23 class ExtensionCompilerPassTest extends TestCase
24 {
25     private $container;
26     private $pass;
27
28     protected function setUp()
29     {
30         $this->container = new ContainerBuilder();
31         $this->pass = new ExtensionCompilerPass();
32     }
33
34     public function testProcess()
35     {
36         $extension1 = new CompilerPassExtension('extension1');
37         $extension2 = new DummyExtension('extension2');
38         $extension3 = new DummyExtension('extension3');
39         $extension4 = new CompilerPassExtension('extension4');
40
41         $this->container->registerExtension($extension1);
42         $this->container->registerExtension($extension2);
43         $this->container->registerExtension($extension3);
44         $this->container->registerExtension($extension4);
45
46         $this->pass->process($this->container);
47
48         $this->assertTrue($this->container->hasDefinition('extension1'));
49         $this->assertFalse($this->container->hasDefinition('extension2'));
50         $this->assertFalse($this->container->hasDefinition('extension3'));
51         $this->assertTrue($this->container->hasDefinition('extension4'));
52     }
53 }
54
55 class DummyExtension extends Extension
56 {
57     private $alias;
58
59     public function __construct($alias)
60     {
61         $this->alias = $alias;
62     }
63
64     public function getAlias()
65     {
66         return $this->alias;
67     }
68
69     public function load(array $configs, ContainerBuilder $container)
70     {
71     }
72
73     public function process(ContainerBuilder $container)
74     {
75         $container->register($this->alias);
76     }
77 }
78
79 class CompilerPassExtension extends DummyExtension implements CompilerPassInterface
80 {
81 }