[FrameworkBundle]Ignore LoggingTranslatorPass if there is no Translator definition.

This commit is contained in:
Abdellatif Ait boudad 2014-09-24 22:15:22 +01:00
parent cc04ce15c0
commit 6e1b47c3fd
2 changed files with 17 additions and 2 deletions

View File

@ -21,7 +21,7 @@ class LoggingTranslatorPass implements CompilerPassInterface
{ {
public function process(ContainerBuilder $container) public function process(ContainerBuilder $container)
{ {
if (!$container->hasAlias('logger')) { if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
return; return;
} }

View File

@ -23,7 +23,7 @@ class LoggingTranslatorPassTest extends \PHPUnit_Framework_TestCase
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$parameterBag = $this->getMock('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface'); $parameterBag = $this->getMock('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface');
$container->expects($this->once()) $container->expects($this->exactly(2))
->method('hasAlias') ->method('hasAlias')
->will($this->returnValue(true)); ->will($this->returnValue(true));
@ -65,4 +65,19 @@ class LoggingTranslatorPassTest extends \PHPUnit_Framework_TestCase
$pass = new LoggingTranslatorPass(); $pass = new LoggingTranslatorPass();
$pass->process($container); $pass->process($container);
} }
public function testThatCompilerPassIsIgnoredIfThereIsNotTranslatorDefinition()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$container->expects($this->at(0))
->method('hasAlias')
->will($this->returnValue(true));
$container->expects($this->at(0))
->method('hasAlias')
->will($this->returnValue(false));
$pass = new LoggingTranslatorPass();
$pass->process($container);
}
} }