FileLinkFormatterTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 testWhenFileLinkFormatAndRequest()
  29. {
  30. $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
  31. $requestStack = new RequestStack();
  32. $request = new Request();
  33. $requestStack->push($request);
  34. $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
  35. $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
  36. }
  37. public function testWhenNoFileLinkFormatAndRequest()
  38. {
  39. $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
  40. $requestStack = new RequestStack();
  41. $request = new Request();
  42. $requestStack->push($request);
  43. $request->server->set('SERVER_NAME', 'www.example.org');
  44. $request->server->set('SERVER_PORT', 80);
  45. $request->server->set('SCRIPT_NAME', '/index.php');
  46. $request->server->set('SCRIPT_FILENAME', '/public/index.php');
  47. $request->server->set('REQUEST_URI', '/index.php/example');
  48. $sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
  49. $this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
  50. }
  51. }