No Description

FileLinkFormatterTest.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
  14. class FileLinkFormatterTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testWhenNoFileLinkFormatAndNoRequest()
  17. {
  18. $sut = new FileLinkFormatter();
  19. $this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
  20. }
  21. public function testWhenFileLinkFormatAndNoRequest()
  22. {
  23. $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
  24. $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
  25. $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
  26. }
  27. public function testWhenFileLinkFormatAndRequest()
  28. {
  29. $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
  30. $baseDir = __DIR__;
  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', '/app.php');
  46. $request->server->set('SCRIPT_FILENAME', '/web/app.php');
  47. $request->server->set('REQUEST_URI', '/app.php/example');
  48. $sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
  49. $this->assertSame('http://www.example.org/app.php/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
  50. }
  51. }