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();