|
4 | 4 |
|
5 | 5 | use Nyholm\BundleTest\TestKernel;
|
6 | 6 | use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\ConfigurationBundle;
|
| 7 | +use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\DeRegisterSomethingPass; |
| 8 | +use Nyholm\BundleTest\Tests\Fixtures\ConfigurationBundle\DependencyInjection\Compiler\RegisterSomethingPass; |
7 | 9 | use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
| 10 | +use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
8 | 11 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
9 | 12 | use Symfony\Component\HttpKernel\KernelInterface;
|
10 | 13 |
|
@@ -61,4 +64,41 @@ public function testBundleWithDifferentConfigurationFormats($config): void
|
61 | 64 | $this->assertEquals('val1', $container->getParameter('app.foo'));
|
62 | 65 | $this->assertEquals(['val2', 'val3'], $container->getParameter('app.bar'));
|
63 | 66 | }
|
| 67 | + |
| 68 | + public function testAddCompilerPassPriority(): void |
| 69 | + { |
| 70 | + // CASE 1: Compiler pass without priority, should be prioritized by order of addition |
| 71 | + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { |
| 72 | + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); |
| 73 | + $kernel->addTestCompilerPass(new DeRegisterSomethingPass()); |
| 74 | + $kernel->addTestCompilerPass(new RegisterSomethingPass()); |
| 75 | + }]); |
| 76 | + |
| 77 | + $container = $kernel->getContainer(); |
| 78 | + |
| 79 | + $this->assertTrue($container->has('something')); |
| 80 | + |
| 81 | + // CASE 2: Compiler pass with priority, should be prioritized by priority |
| 82 | + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { |
| 83 | + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); |
| 84 | + $kernel->addTestCompilerPass(new DeRegisterSomethingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -5); |
| 85 | + $kernel->addTestCompilerPass(new RegisterSomethingPass()); |
| 86 | + }]); |
| 87 | + |
| 88 | + $container = $kernel->getContainer(); |
| 89 | + |
| 90 | + $this->assertFalse($container->has('something')); |
| 91 | + |
| 92 | + // CASE 3: Compiler pass without priority, should be prioritized by order of addition |
| 93 | + $kernel = self::bootKernel(['config' => function (TestKernel $kernel) { |
| 94 | + $kernel->addTestConfig(__DIR__.'/../Fixtures/Resources/ConfigurationBundle/config.php'); |
| 95 | + // DeRegisterSomethingPass is now added as second compiler pass |
| 96 | + $kernel->addTestCompilerPass(new RegisterSomethingPass()); |
| 97 | + $kernel->addTestCompilerPass(new DeRegisterSomethingPass()); |
| 98 | + }]); |
| 99 | + |
| 100 | + $container = $kernel->getContainer(); |
| 101 | + |
| 102 | + $this->assertFalse($container->has('something')); |
| 103 | + } |
64 | 104 | }
|
0 commit comments