/
WebProfilerExtensionTest.php
56 lines (44 loc) · 1.85 KB
/
WebProfilerExtensionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\WebProfilerBundle\Tests\Twig;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Twig\Environment;
class WebProfilerExtensionTest extends TestCase
{
/**
* @dataProvider provideMessages
*/
public function testDumpHeaderIsDisplayed(string $message, array $context, bool $dump1HasHeader, bool $dump2HasHeader)
{
$twigEnvironment = $this->mockTwigEnvironment();
$varCloner = new VarCloner();
$webProfilerExtension = new WebProfilerExtension();
$needle = 'window.Sfdump';
$dump1 = $webProfilerExtension->dumpLog($twigEnvironment, $message, $varCloner->cloneVar($context));
self::assertSame($dump1HasHeader, str_contains($dump1, $needle));
$dump2 = $webProfilerExtension->dumpData($twigEnvironment, $varCloner->cloneVar([]));
self::assertSame($dump2HasHeader, str_contains($dump2, $needle));
}
public static function provideMessages(): iterable
{
yield ['Some message', ['foo' => 'foo', 'bar' => 'bar'], false, true];
yield ['Some message {@see some text}', ['foo' => 'foo', 'bar' => 'bar'], false, true];
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;
}
}