1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
/**
* @author Wouter J <wouter@wouterj.nl>
*/
class ExtensionCompilerPassTest extends TestCase
{
private $container;
private $pass;
protected function setUp(): void
{
$this->container = new ContainerBuilder();
$this->pass = new ExtensionCompilerPass();
}
public function testProcess()
{
$extension1 = new CompilerPassExtension('extension1');
$extension2 = new DummyExtension('extension2');
$extension3 = new DummyExtension('extension3');
$extension4 = new CompilerPassExtension('extension4');
$this->container->registerExtension($extension1);
$this->container->registerExtension($extension2);
$this->container->registerExtension($extension3);
$this->container->registerExtension($extension4);
$this->pass->process($this->container);
$this->assertTrue($this->container->hasDefinition('extension1'));
$this->assertFalse($this->container->hasDefinition('extension2'));
$this->assertFalse($this->container->hasDefinition('extension3'));
$this->assertTrue($this->container->hasDefinition('extension4'));
}
}
class DummyExtension extends Extension
{
private $alias;
public function __construct($alias)
{
$this->alias = $alias;
}
public function getAlias()
{
return $this->alias;
}
public function load(array $configs, ContainerBuilder $container)
{
}
public function process(ContainerBuilder $container)
{
$container->register($this->alias);
}
}
class CompilerPassExtension extends DummyExtension implements CompilerPassInterface
{
}