4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Debug;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\RequestStack;
17 use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
19 class FileLinkFormatterTest extends TestCase
21 public function testWhenNoFileLinkFormatAndNoRequest()
23 $sut = new FileLinkFormatter();
25 $this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
28 public function testWhenFileLinkFormatAndNoRequest()
30 $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
32 $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
34 $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
37 public function testWhenFileLinkFormatAndRequest()
39 $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
41 $requestStack = new RequestStack();
42 $request = new Request();
43 $requestStack->push($request);
45 $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
47 $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
50 public function testWhenNoFileLinkFormatAndRequest()
52 $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
53 $requestStack = new RequestStack();
54 $request = new Request();
55 $requestStack->push($request);
57 $request->server->set('SERVER_NAME', 'www.example.org');
58 $request->server->set('SERVER_PORT', 80);
59 $request->server->set('SCRIPT_NAME', '/app.php');
60 $request->server->set('SCRIPT_FILENAME', '/web/app.php');
61 $request->server->set('REQUEST_URI', '/app.php/example');
63 $sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
65 $this->assertSame('http://www.example.org/app.php/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));