Skip to content

Commit

Permalink
Merge pull request #155 from danrot/bugfix/formular-loader-reset
Browse files Browse the repository at this point in the history
reset theme after assetic loader has been called
  • Loading branch information
lsmith77 authored Nov 23, 2016
2 parents c6ccf16 + 566699e commit 2071de9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Assetic/TwigFormulaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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])) {
Expand Down
13 changes: 12 additions & 1 deletion Tests/Assetic/TwigFormulaLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()));
Expand All @@ -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();
Expand Down

0 comments on commit 2071de9

Please sign in to comment.