From e78379e568fa44fc7a58ae139c3d1924b7f05c61 Mon Sep 17 00:00:00 2001 From: adaniloff Date: Thu, 8 Oct 2020 15:40:08 +0200 Subject: [PATCH 1/4] Change ExceptionListenerPass removeDefinition args --- .../DependencyInjection/Compiler/ExceptionListenerPass.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php index c21507dca8f1e..dfa9989848287 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php @@ -40,12 +40,12 @@ public function process(ContainerBuilder $container) if ($container->hasParameter('templating.engines')) { $engines = $container->getParameter('templating.engines'); if (\in_array('twig', $engines, true)) { - $container->removeDefinition('exception_listener'); + $container->removeDefinition('twig.exception_listener'); return; } } - $container->removeDefinition('twig.exception_listener'); + $container->removeDefinition('exception_listener'); } } From 4c5b1f261b9f152beb9228765383d51b483dbcbd Mon Sep 17 00:00:00 2001 From: adaniloff Date: Fri, 9 Oct 2020 10:47:38 +0200 Subject: [PATCH 2/4] test: fix class ExceptionListenerPassTest Make the test class so it covers the initial behavior on 4.4.14, prior to the 4.4.15 release. --- .../Compiler/ExceptionListenerPassTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php index cc7558f6e6ce7..7a600efacf08e 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php @@ -46,9 +46,26 @@ public function testRemovesTwigExceptionListenerWhenNoExceptionListenerControlle $this->assertTrue($builder->hasDefinition('exception_listener')); $this->assertFalse($builder->hasDefinition('twig.exception_listener')); } + + public function testRemovesBothExceptionListenerIfTwigIsNotUsedAsTemplateEngine(): void + { + $builder = new ContainerBuilder(); + $builder->register('twig', Environment::class); + $builder->register('exception_listener', ExceptionListener::class); + $builder->register('twig.exception_listener', ExceptionListener::class); + $builder->setParameter('twig.exception_listener.controller', 'exception_controller::showAction'); + $builder->setParameter('templating.engines', ['php']); + + ($pass = new ExceptionListenerPass())->process($builder); + + $this->assertFalse($builder->hasDefinition('exception_listener')); + $this->assertFalse($builder->hasDefinition('twig.exception_listener')); + } public function testRemovesTwigExceptionListenerIfTwigIsNotUsedAsTemplateEngine(): void { + $this->markTestSkipped(sprintf('This test was implemented in accordance to version %. However, the implementation which this test cover was a behavior change.', '4.4.15')); + $builder = new ContainerBuilder(); $builder->register('twig', Environment::class); $builder->register('exception_listener', ExceptionListener::class); From a1819e75a78fc58d05b168e90adbde8f5eac26f1 Mon Sep 17 00:00:00 2001 From: adaniloff Date: Fri, 9 Oct 2020 10:48:51 +0200 Subject: [PATCH 3/4] fix: ExceptionListenerPass definition removal According the the previous commit; in order to keep it consistent with 4.4.14 version. --- .../DependencyInjection/Compiler/ExceptionListenerPass.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php index dfa9989848287..57823408dbd26 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExceptionListenerPass.php @@ -39,10 +39,8 @@ public function process(ContainerBuilder $container) if ($container->hasParameter('templating.engines')) { $engines = $container->getParameter('templating.engines'); - if (\in_array('twig', $engines, true)) { + if (!\in_array('twig', $engines, true)) { $container->removeDefinition('twig.exception_listener'); - - return; } } From c322ce006677a72325ae7985f9da7a5747038b0b Mon Sep 17 00:00:00 2001 From: adaniloff Date: Fri, 9 Oct 2020 10:52:01 +0200 Subject: [PATCH 4/4] style: fix changes style --- .../Compiler/ExceptionListenerPassTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php index 7a600efacf08e..b4298297b14bd 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/ExceptionListenerPassTest.php @@ -46,7 +46,7 @@ public function testRemovesTwigExceptionListenerWhenNoExceptionListenerControlle $this->assertTrue($builder->hasDefinition('exception_listener')); $this->assertFalse($builder->hasDefinition('twig.exception_listener')); } - + public function testRemovesBothExceptionListenerIfTwigIsNotUsedAsTemplateEngine(): void { $builder = new ContainerBuilder(); @@ -65,7 +65,7 @@ public function testRemovesBothExceptionListenerIfTwigIsNotUsedAsTemplateEngine( public function testRemovesTwigExceptionListenerIfTwigIsNotUsedAsTemplateEngine(): void { $this->markTestSkipped(sprintf('This test was implemented in accordance to version %. However, the implementation which this test cover was a behavior change.', '4.4.15')); - + $builder = new ContainerBuilder(); $builder->register('twig', Environment::class); $builder->register('exception_listener', ExceptionListener::class);