From 8aa9fe7681eaabe6285aa76d0a52e9da4ff67ffa Mon Sep 17 00:00:00 2001 From: Warnar Boekkooi Date: Thu, 12 May 2016 10:07:24 +0200 Subject: [PATCH] Fixed AsseticTwigLoader patching to use the correct service --- .../Compiler/ExclamationPass.php | 5 +++- .../Compiler/ExclamationPassTest.php | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/Compiler/ExclamationPass.php b/src/DependencyInjection/Compiler/ExclamationPass.php index ca399a3..61a9a71 100644 --- a/src/DependencyInjection/Compiler/ExclamationPass.php +++ b/src/DependencyInjection/Compiler/ExclamationPass.php @@ -32,7 +32,10 @@ public function process(ContainerBuilder $container) ->addArgument(new Reference('kernel')); // Patch assetic service when availible - if ($container->hasDefinition('assetic.twig_formula_loader')) { + if ($container->hasDefinition('assetic.twig_formula_loader.real')) { + $container->getDefinition('assetic.twig_formula_loader.real') + ->setClass('%assetic.twig_formula_loader.class%'); + } elseif ($container->hasDefinition('assetic.twig_formula_loader')) { $container->getDefinition('assetic.twig_formula_loader') ->setClass('%assetic.twig_formula_loader.class%'); } diff --git a/tests/DependencyInjection/Compiler/ExclamationPassTest.php b/tests/DependencyInjection/Compiler/ExclamationPassTest.php index ede9056..de52bde 100644 --- a/tests/DependencyInjection/Compiler/ExclamationPassTest.php +++ b/tests/DependencyInjection/Compiler/ExclamationPassTest.php @@ -43,6 +43,28 @@ public function it_should_change_the_templating_services_when_enabled() * @test */ public function it_should_change_the_assetic_service_when_enabled() + { + $this->setDefinition('templating.name_parser', new Definition(__CLASS__)); + $this->setDefinition('templating.cache_warmer.template_paths', new Definition(__CLASS__)); + $this->setDefinition('assetic.twig_formula_loader.real', new Definition(__CLASS__)); + $this->setDefinition('assetic.twig_formula_loader', new Definition(__CLASS__)); + + $this->setParameter('boekkooi.twig_jack.exclamation', true); + + $this->setParameter('templating.name_parser.class', 'DummyNameParser'); + $this->setParameter('templating.cache_warmer.template_paths.class', 'DummyTemplatePaths'); + $this->setParameter('assetic.twig_formula_loader.class', 'DummyAssetic'); + + $this->compile(); + + $this->assertContainerBuilderHasService('assetic.twig_formula_loader.real', 'DummyAssetic'); + $this->assertContainerBuilderHasService('assetic.twig_formula_loader', __CLASS__); + } + + /** + * @test + */ + public function it_should_change_the_assetic_service_when_enabled_fallback() { $this->setDefinition('templating.name_parser', new Definition(__CLASS__)); $this->setDefinition('templating.cache_warmer.template_paths', new Definition(__CLASS__)); @@ -57,6 +79,7 @@ public function it_should_change_the_assetic_service_when_enabled() $this->compile(); $this->assertContainerBuilderHasService('assetic.twig_formula_loader', 'DummyAssetic'); + $this->assertContainerBuilderNotHasService('assetic.twig_formula_loader.real'); } /**