8000 [WebProfilerBundle] fix compatibility with Twig 3.10 by xabbuh · Pull Request #54800 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebProfilerBundle] fix compatibility with Twig 3.10 #54800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

class WebProfilerExtensionTest extends TestCase
{
Expand All @@ -23,7 +24,7 @@ class WebProfilerExtensionTest extends TestCase
*/
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
{
$twigEnvironment = $this->mockTwigEnvironment();
$twigEnvironment = new Environment(new ArrayLoader());
$varCloner = new VarCloner();

$webProfilerExtension = new WebProfilerExtension();
Expand All @@ -44,13 +45,4 @@ public static function provideMessages(): iterable
yield ['Some message {foo}', ['foo' => 'foo', 'bar' => 'bar'], true, false];
yield ['Some message {foo}', ['bar' => 'bar'], false, true];
}

private function mockTwigEnvironment()
{
$twigEnvironment = $this->createMock(Environment::class);

$twigEnvironment->expects($this->any())->method('getCharset')->willReturn('UTF-8');

return $twigEnvironment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Twig\Extension\EscaperExtension;
use Twig\Extension\ProfilerExtension;
use Twig\Profiler\Profile;
use Twig\Runtime\EscaperRuntime;
use Twig\TwigFunction;

/**
Expand Down Expand Up @@ -114,6 +115,12 @@ public function getName()

private static function escape(Environment $env, string $s): string
{
// Twig 3.10 and above
if (class_exists(EscaperRuntime::class)) {
return $env->getRuntime(EscaperRuntime::class)->escape($s);
}

// Twig 3.9
if (method_exists(EscaperExtension::class, 'escape')) {
return EscaperExtension::escape($env, $s);
}
Expand Down
Loading
0