Skip to content

Commit ffc6e9b

Browse files
author
Amrouche Hamza
committed
[Profiler][Translation] Logging false by default and desactivated when using the profiler
1 parent a522e04 commit ffc6e9b

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public function process(ContainerBuilder $container)
2727
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
2828
return;
2929
}
30+
if ($container->has('profiler') && $container->hasParameter('translator.logging')) {
31+
$container->setParameter('translator.logging', false);
32+
}
3033

3134
if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
3235
$translatorAlias = $container->getAlias('translator');

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
622622
->prototype('scalar')->end()
623623
->defaultValue(array('en'))
624624
->end()
625-
->booleanNode('logging')->defaultValue($this->debug)->end()
625+
->booleanNode('logging')->defaultValue(false)->end()
626626
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
627627
->arrayNode('paths')
628628
->prototype('scalar')->end()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testProcess()
3838
->method('getDefinition')
3939
->will($this->returnValue($definition));
4040

41-
$container->expects($this->once())
41+
$container->expects($this->atLeastOnce())
4242
->method('hasParameter')
4343
->with('translator.logging')
4444
->will($this->returnValue(true));
@@ -80,6 +80,60 @@ public function testProcess()
8080
$pass->process($container);
8181
}
8282

83+
public function testProcessWithProfiler()
84+
{
85+
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
86+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->getMock();
87+
$parameterBag = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface')->getMock();
88+
89+
$container->expects($this->exactly(2))
90+
->method('hasAlias')
91+
->will($this->returnValue(true));
92+
93+
$container->expects($this->once())
94+
->method('getParameter')
95+
->will($this->returnValue(true));
96+
97+
$container->expects($this->once())
98+
->method('getAlias')
99+
->will($this->returnValue('translation.default'));
100+
101+
$container->expects($this->exactly(3))
102+
->method('getDefinition')
103+
->will($this->returnValue($definition));
104+
105+
$container->expects($this->atLeastOnce())
106+
->method('hasParameter')
107+
->with('translator.logging')
108+
->will($this->returnValue(true));
109+
110+
$container->expects($this->atLeastOnce())
111+
->method('setParameter')
112+
->with('translator.logging')
113+
->will($this->returnValue(true));
114+
115+
$container->expects($this->atLeastOnce())
116+
->method('has')
117+
->with('profiler')
118+
->will($this->returnValue(true));
119+
120+
$parameterBag->expects($this->once())
121+
->method('resolveValue')
122+
->will($this->returnValue("Symfony\Bundle\FrameworkBundle\Translation\Translator"));
123+
124+
$container->expects($this->once())
125+
->method('getParameterBag')
126+
->will($this->returnValue($parameterBag));
127+
128+
$container->expects($this->once())
129+
->method('getReflectionClass')
130+
->with('Symfony\Bundle\FrameworkBundle\Translation\Translator')
131+
->will($this->returnValue(new \ReflectionClass('Symfony\Bundle\FrameworkBundle\Translation\Translator')));
132+
133+
$pass = new LoggingTranslatorPass();
134+
$pass->process($container);
135+
}
136+
83137
public function testThatCompilerPassIsIgnoredIfThereIsNotLoggerDefinition()
84138
{
85139
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->getMock();

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected static function getBundleDefaultConfig()
152152
'translator' => array(
153153
'enabled' => !class_exists(FullStack::class),
154154
'fallbacks' => array('en'),
155-
'logging' => true,
155+
'logging' => false,
156156
'formatter' => 'translator.formatter.default',
157157
'paths' => array(),
158158
),

0 commit comments

Comments
 (0)