public function testGetResponseForException() { $em = new EventManager(); $em->addEventListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) { $event->setResponse(Response::createFromRequest($event->getRequest(), $event->getException()->getMessage())); }); $kernel = new HttpKernel($em, new ClosureControllerFactory()); $response = $kernel->handle(Request::create('GET', '/home')); $this->assertSame('NO CONTROLLER FOUND!', $response->getBody()); }
public function testStopRequestEvent() { $request = new Request('GET', '/home', 'HTTP', '1.1'); $response = Response::createFromRequest($request, '', 200); $event = new KernelEvent($request); $this->assertSame($request, $event->getRequest()); $this->assertNull($event->getResponse()); $this->assertFalse($event->hasResponse()); $this->assertFalse($event->isStopped()); $event->setResponse($response); $this->assertTrue($event->hasResponse()); $this->assertSame($response, $event->getResponse()); $this->assertTrue($event->isStopped()); }
private function createResponse(RequestInterface $request, $content, $statusCode = ResponseInterface::HTTP_OK) { return Response::createFromRequest($request, $content, $statusCode); }
public function handle(Request $request) { return Response::createFromRequest($request, 'DUMMY!'); }