You are here

public function HttpKernelTest::testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHandlingListener in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/Tests/HttpKernelTest.php \Symfony\Component\HttpKernel\Tests\HttpKernelTest::testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHandlingListener()

File

vendor/symfony/http-kernel/Tests/HttpKernelTest.php, line 46

Class

HttpKernelTest

Namespace

Symfony\Component\HttpKernel\Tests

Code

public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHandlingListener() {
  $dispatcher = new EventDispatcher();
  $dispatcher
    ->addListener(KernelEvents::EXCEPTION, function ($event) {
    $event
      ->setResponse(new Response($event
      ->getException()
      ->getMessage()));
  });
  $kernel = new HttpKernel($dispatcher, $this
    ->getResolver(function () {
    throw new \RuntimeException('foo');
  }));
  $response = $kernel
    ->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
  $this
    ->assertEquals('500', $response
    ->getStatusCode());
  $this
    ->assertEquals('foo', $response
    ->getContent());
}