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';
40 $requestStack = new RequestStack();
41 $request = new Request();
42 $requestStack->push($request);
44 $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
46 $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
49 public function testWhenNoFileLinkFormatAndRequest()
51 $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
52 $requestStack = new RequestStack();
53 $request = new Request();
54 $requestStack->push($request);
56 $request->server->set('SERVER_NAME', 'www.example.org');
57 $request->server->set('SERVER_PORT', 80);
58 $request->server->set('SCRIPT_NAME', '/index.php');
59 $request->server->set('SCRIPT_FILENAME', '/public/index.php');
60 $request->server->set('REQUEST_URI', '/index.php/example');
62 $sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
64 $this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));