예제 #1
0
 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());
 }
예제 #2
0
 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());
 }
예제 #3
0
 private function createResponse(RequestInterface $request, $content, $statusCode = ResponseInterface::HTTP_OK)
 {
     return Response::createFromRequest($request, $content, $statusCode);
 }
예제 #4
0
 public function handle(Request $request)
 {
     return Response::createFromRequest($request, 'DUMMY!');
 }