Skip to content

Commit bd66165

Browse files
committed
feature #11549 [Bundle][FrameworkBundle] make the stopwatch service always available (xabbuh)
This PR was merged into the 2.6-dev branch. Discussion ---------- [Bundle][FrameworkBundle] make the stopwatch service always available | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11347 | License | MIT | Doc PR | Previously, one had to be careful to check if the ``debug.stopwatch`` service was available before using it. Otherwise, the application would break in the prod environment. Commits ------- ffc4090 make the stopwatch service always available
2 parents fe57e5a + 5e262ac commit bd66165

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Resources/config/twig.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<service id="twig.extension.debug.stopwatch" class="%twig.extension.debug.stopwatch.class%" public="false">
9393
<tag name="twig.extension" />
9494
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
95+
<argument>%kernel.debug%</argument>
9596
</service>
9697

9798
<service id="twig.extension.expression" class="%twig.extension.expression.class%" public="false">

Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,37 @@ public function getFormats()
179179
);
180180
}
181181

182+
/**
183+
* @dataProvider stopwatchExtensionAvailabilityProvider
184+
*/
185+
public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $expected)
186+
{
187+
$container = $this->createContainer();
188+
$container->setParameter('kernel.debug', $debug);
189+
if ($stopwatchEnabled) {
190+
$container->register('debug.stopwatch', 'Symfony\Component\Stopwatch\Stopwatch');
191+
}
192+
$container->registerExtension(new TwigExtension());
193+
$container->loadFromExtension('twig', array());
194+
$this->compileContainer($container);
195+
196+
$tokenParsers = $container->get('twig.extension.debug.stopwatch')->getTokenParsers();
197+
$stopwatchIsAvailable = new \ReflectionProperty($tokenParsers[0], 'stopwatchIsAvailable');
198+
$stopwatchIsAvailable->setAccessible(true);
199+
200+
$this->assertSame($expected, $stopwatchIsAvailable->getValue($tokenParsers[0]));
201+
}
202+
203+
public function stopwatchExtensionAvailabilityProvider()
204+
{
205+
return array(
206+
'debug-and-stopwatch-enabled' => array(true, true, true),
207+
'only-stopwatch-enabled' => array(false, true, false),
208+
'only-debug-enabled' => array(true, false, false),
209+
'debug-and-stopwatch-disabled' => array(false, false, false),
210+
);
211+
}
212+
182213
private function createContainer()
183214
{
184215
$container = new ContainerBuilder(new ParameterBag(array(

0 commit comments

Comments
 (0)