From 566699edd2c81366c36e501d4d9f791d6da5c5a0 Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Wed, 16 Nov 2016 16:29:53 +0100 Subject: [PATCH] reset theme after assetic loader has been called --- Assetic/TwigFormulaLoader.php | 4 ++++ Tests/Assetic/TwigFormulaLoaderTest.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Assetic/TwigFormulaLoader.php b/Assetic/TwigFormulaLoader.php index 6650f72..b8a2466 100644 --- a/Assetic/TwigFormulaLoader.php +++ b/Assetic/TwigFormulaLoader.php @@ -51,6 +51,8 @@ public function load(ResourceInterface $resource) $failureTemplates = array(); $successTemplates = array(); + $previousTheme = $this->activeTheme->getName(); + foreach ($this->activeTheme->getThemes() as $theme) { $this->activeTheme->setName($theme); @@ -71,6 +73,8 @@ public function load(ResourceInterface $resource) } } + $this->activeTheme->setName($previousTheme); + if ($this->logger) { foreach ($failureTemplates as $failureTemplate => $exceptionMessage) { if (isset($successTemplates[$failureTemplate])) { diff --git a/Tests/Assetic/TwigFormulaLoaderTest.php b/Tests/Assetic/TwigFormulaLoaderTest.php index 01892ae..cc0b3ee 100644 --- a/Tests/Assetic/TwigFormulaLoaderTest.php +++ b/Tests/Assetic/TwigFormulaLoaderTest.php @@ -36,8 +36,16 @@ class TwigFormulaLoaderTest extends \PHPUnit_Framework_TestCase */ private $resource; + /** + * @var string + */ private $resourceContent; + /** + * @var TwigFormulaLoaderTest + */ + private $loader; + public function setUp() { $this->twig = $this->prophesize('Twig_Environment'); @@ -61,7 +69,9 @@ public function testLoader() 'theme1', 'theme2', )); - $this->activeTheme->setName('theme1')->shouldBeCalled(); + $this->activeTheme->getName()->willReturn('theme1'); + + $this->activeTheme->setName('theme1')->shouldBeCalledTimes(2); $this->activeTheme->setName('theme2')->shouldBeCalled(); $this->twig->tokenize(Argument::any(), Argument::any())->shouldBeCalled()->willReturn(new \Twig_TokenStream(array())); @@ -75,6 +85,7 @@ public function testExceptions() $this->activeTheme->getThemes()->willReturn(array( 'theme1', )); + $this->activeTheme->getName()->willReturn('theme1'); $this->activeTheme->setName('theme1')->shouldBeCalled(); $this->twig->tokenize(Argument::any())->willThrow(new \Exception('foobar')); $this->logger->error('The template "foo" contains an error: "foobar"')->shouldBeCalled();