FileLinkFormatterTest.php 2.3 KB

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