Skip to content

Commit

Permalink
Fixed AsseticTwigLoader patching to use the correct service
Browse files Browse the repository at this point in the history
  • Loading branch information
boekkooi committed May 12, 2016
1 parent 0104dca commit 8aa9fe7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/DependencyInjection/Compiler/ExclamationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%');
}
Expand Down
23 changes: 23 additions & 0 deletions tests/DependencyInjection/Compiler/ExclamationPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__));
Expand All @@ -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');
}

/**
Expand Down

0 comments on commit 8aa9fe7

Please sign in to comment.