diff --git a/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeregisterSomethingPass.php b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeregisterSomethingPass.php new file mode 100644 index 0000000..250f8dd --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/DeregisterSomethingPass.php @@ -0,0 +1,17 @@ +hasDefinition('something')) { + $container->removeDefinition('something'); + } + } +} diff --git a/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php new file mode 100644 index 0000000..25bf8b2 --- /dev/null +++ b/tests/Fixtures/ConfigurationBundle/DependencyInjection/Compiler/RegisterSomethingPass.php @@ -0,0 +1,24 @@ +hasDefinition('something')) { + return; + } + + $definition = new Definition(); + $definition->setClass(\stdClass::class); + $definition->setPublic(true); + + $container->setDefinition('something', $definition); + } +} diff --git a/tests/Functional/CompilerPassTest.php b/tests/Functional/CompilerPassTest.php new file mode 100644 index 0000000..a0e8d29 --- /dev/null +++ b/tests/Functional/CompilerPassTest.php @@ -0,0 +1,44 @@ + function (TestKernel $kernel) { + $kernel->addTestCompilerPass(new DeregisterSomethingPass()); + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + }]); + + $this->assertTrue(self::getContainer()->has('something')); + + // Case 2: Compiler pass with priority - it should be prioritized by priority + self::bootKernel(['config' => function (TestKernel $kernel) { + $kernel->addTestCompilerPass(new DeregisterSomethingPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -5); + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + }]); + + $this->assertFalse(self::getContainer()->has('something')); + + // Case 3: Compiler pass without priority - it should be prioritized by order of addition + self::bootKernel(['config' => function (TestKernel $kernel) { + // DeregisterSomethingPass is now added as second compiler pass + $kernel->addTestCompilerPass(new RegisterSomethingPass()); + $kernel->addTestCompilerPass(new DeregisterSomethingPass()); + }]); + + $this->assertFalse(self::getContainer()->has('something')); + } +}