FileLinkFormatterTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\Debug;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\RequestStack;
  14. use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
  15. class FileLinkFormatterTest extends TestCase
  16. {
  17. public function testWhenNoFileLinkFormatAndNoRequest()
  18. {
  19. $sut = new FileLinkFormatter([]);
  20. $this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
  21. }
  22. public function testWhenFileLinkFormatAndNoRequest()
  23. {
  24. $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
  25. $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
  26. $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
  27. }
  28. public function testWhenNoFileLinkFormatAndRequest()
  29. {
  30. $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
  31. $requestStack = new RequestStack();
  32. $request = new Request();
  33. $requestStack->push($request);
  34. $request->server->set('SERVER_NAME', 'www.example.org');
  35. $request->server->set('SERVER_PORT', 80);
  36. $request->server->set('SCRIPT_NAME', '/index.php');
  37. $request->server->set('SCRIPT_FILENAME', '/public/index.php');
  38. $request->server->set('REQUEST_URI', '/index.php/example');
  39. $sut = new FileLinkFormatter([], $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
  40. $this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
  41. }
  42. public function testIdeFileLinkFormat()
  43. {
  44. $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
  45. $sut = new FileLinkFormatter('atom');
  46. $this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3));
  47. }
  48. }