PreviewErrorControllerTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Bundle\TwigBundle\Tests\Controller;
  11. use Symfony\Bundle\TwigBundle\Controller\PreviewErrorController;
  12. use Symfony\Bundle\TwigBundle\Tests\TestCase;
  13. use Symfony\Component\Debug\Exception\FlattenException;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpKernel\HttpKernelInterface;
  17. class PreviewErrorControllerTest extends TestCase
  18. {
  19. public function testForwardRequestToConfiguredController()
  20. {
  21. $request = Request::create('whatever');
  22. $response = new Response('');
  23. $code = 123;
  24. $logicalControllerName = 'foo:bar:baz';
  25. $kernel = $this->getMock('\Symfony\Component\HttpKernel\HttpKernelInterface');
  26. $kernel
  27. ->expects($this->once())
  28. ->method('handle')
  29. ->with(
  30. $this->callback(function (Request $request) use ($logicalControllerName, $code) {
  31. $this->assertEquals($logicalControllerName, $request->attributes->get('_controller'));
  32. $exception = $request->attributes->get('exception');
  33. $this->assertInstanceOf(FlattenException::class, $exception);
  34. $this->assertEquals($code, $exception->getStatusCode());
  35. $this->assertFalse($request->attributes->get('showException'));
  36. return true;
  37. }),
  38. $this->equalTo(HttpKernelInterface::SUB_REQUEST)
  39. )
  40. ->will($this->returnValue($response));
  41. $controller = new PreviewErrorController($kernel, $logicalControllerName);
  42. $this->assertSame($response, $controller->previewErrorPageAction($request, $code));
  43. }
  44. }