Skip to content

Commit 3cb63d1

Browse files
[WebProfilerBundle] Fix tests
1 parent e785314 commit 3cb63d1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\WebProfilerBundle\Tests\Profiler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\WebProfilerBundle\Profiler\CodeExtension;
16+
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
17+
18+
class CodeExtensionTest extends TestCase
19+
{
20+
public function testFormatFile()
21+
{
22+
$expected = sprintf('<a href="proto://foobar%s#&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', substr(__FILE__, 5), __FILE__);
23+
$this->assertEquals($expected, $this->getExtension()->formatFile(__FILE__, 25));
24+
}
25+
26+
public function testFileRelative()
27+
{
28+
$this->assertEquals('file.txt', $this->getExtension()->getFileRelative(\DIRECTORY_SEPARATOR.'project'.\DIRECTORY_SEPARATOR.'file.txt'));
29+
}
30+
31+
/**
32+
* @dataProvider getClassNameProvider
33+
*/
34+
public function testGettingClassAbbreviation($class, $abbr)
35+
{
36+
$this->assertEquals($this->getExtension()->abbrClass($class), $abbr);
37+
}
38+
39+
/**
40+
* @dataProvider getMethodNameProvider
41+
*/
42+
public function testGettingMethodAbbreviation($method, $abbr)
43+
{
44+
$this->assertEquals($this->getExtension()->abbrMethod($method), $abbr);
45+
}
46+
47+
public static function getClassNameProvider(): array
48+
{
49+
return [
50+
['F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'],
51+
['Bare', '<abbr title="Bare">Bare</abbr>'],
52+
];
53+
}
54+
55+
public static function getMethodNameProvider(): array
56+
{
57+
return [
58+
['F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'],
59+
['Bare::Method', '<abbr title="Bare">Bare</abbr>::Method()'],
60+
['Closure', '<abbr title="Closure">Closure</abbr>'],
61+
['Method', '<abbr title="Method">Method</abbr>()'],
62+
];
63+
}
64+
65+
protected function getExtension(): CodeExtension
66+
{
67+
return new CodeExtension(new FileLinkFormatter('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar'), \DIRECTORY_SEPARATOR.'project', 'UTF-8');
68+
}
69+
}

0 commit comments

Comments
 (0)