8000 bug #54800 [WebProfilerBundle] fix compatibility with Twig 3.10 (xabbuh) · symfony/symfony@04ee49a · GitHub
[go: up one dir, main page]

Skip to content

Commit 04ee49a

Browse files
committed
bug #54800 [WebProfilerBundle] fix compatibility with Twig 3.10 (xabbuh)
This PR was merged into the 5.4 branch. Discussion ---------- [WebProfilerBundle] fix compatibility with Twig 3.10 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT see twigphp/Twig#4055 Commits ------- a4190b5 fix compatibility with Twig 3.10
2 parents c5e56bb + a4190b5 commit 04ee49a

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Symfony/Bundle/WebProfilerBundle/Tests/Twig/WebProfilerExtensionTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
1616
use Symfony\Component\VarDumper\Cloner\VarCloner;
1717
use Twig\Environment;
18+
use Twig\Loader\ArrayLoader;
1819

1920
class WebProfilerExtensionTest extends TestCase
2021
{
@@ -23,7 +24,7 @@ class WebProfilerExtensionTest extends TestCase
2324
*/
2425
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
2526
{
26-
$twigEnvironment = $this->mockTwigEnvironment();
27+
$twigEnvironment = new Environment(new ArrayLoader());
2728
$varCloner = new VarCloner();
2829

2930
$webProfilerExtension = new WebProfilerExtension();
@@ -44,13 +45,4 @@ public static function provideMessages(): iterable
4445
yield ['Some message {foo}', ['foo' => 'foo', 'bar' => 'bar'], true, false];
4546
yield ['Some message {foo}', ['bar' => 'bar'], false, true];
4647
}
47-
48-
private function mockTwigEnvironment()
49-
{
50-
$twigEnvironment = $this->createMock(Environment::class);
51-
52-
$twigEnvironment->expects($this->any())->method('getCharset')->willReturn('UTF-8');
53-
54-
return $twigEnvironment;
55-
}
5648
}

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Twig\Extension\EscaperExtension;
1818
use Twig\Extension\ProfilerExtension;
1919
use Twig\Profiler\Profile;
20+
use Twig\Runtime\EscaperRuntime;
2021
use Twig\TwigFunction;
2122

2223
/**
@@ -114,6 +115,12 @@ public function getName()
114115

115116
private static function escape(Environment $env, string $s): string
116117
{
118+
// Twig 3.10 and above
119+
if (class_exists(EscaperRuntime::class)) {
120+
return $env->getRuntime(EscaperRuntime::class)->escape($s);
121+
}
122+
123+
// Twig 3.9
117124
if (method_exists(EscaperExtension::class, 'escape')) {
118125
return EscaperExtension::escape($env, $s);
119126
}

0 commit comments

Comments
 (0)
0