Example #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());
 }
Example #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());
 }
    public function testCreateFromMessage()
    {
        $message = <<<Message
HTTP/1.1 404 Page Not Found
content-type: text/html
cache-control: no-cache

<p>
    Sorry, this page does not exist!
</p>
Message;
        $response = Response::createFromMessage($message);
        $this->assertSame(404, $response->getStatusCode());
        $this->assertSame("Page Not Found", $response->getReasonPhrase());
        $this->assertCount(2, $response->getHeaders());
        $this->assertSame("text/html", $response->getHeader("content-type"));
        $this->assertSame("no-cache", $response->getHeader("cache-control"));
        $this->assertSame("HTTP", $response->getScheme());
        $this->assertSame("1.1", $response->getSchemeVersion());
        $this->assertContains('page does not', $response->getBody());
        $this->assertSame($message, $response->getMessage());
        $this->assertSame($message, (string) $response);
    }
    public function testCreateFromMessage()
    {
        $message = <<<MESSAGE
HTTP/1.1 404 Page Not Found
content-type: text/html
cache-control: no-cache

<p>
    Sorry, this page does not exist!
</p>
MESSAGE;
        $response = Response::createFromMessage($message);
        $this->assertSame(404, $response->getStatusCode());
        $this->assertSame('Page Not Found', $response->getReasonPhrase());
        $this->assertCount(2, $response->getHeaders());
        $this->assertSame('text/html', $response->getHeader('content-type'));
        $this->assertSame('no-cache', $response->getHeader('cache-control'));
        $this->assertSame('HTTP', $response->getScheme());
        $this->assertSame('1.1', $response->getSchemeVersion());
        $this->assertContains('page does not', $response->getBody());
        $this->assertSame($message, $response->getMessage());
        $this->assertSame($message, (string) $response);
    }
Example #5
0
 private function createResponse(RequestInterface $request, $content, $statusCode = ResponseInterface::HTTP_OK)
 {
     return Response::createFromRequest($request, $content, $statusCode);
 }
Example #6
0
 /**
  * @expectedException \Framework\Http\MalformedHttpMessageException
  * @dataProvider provideInvalidMessage
  */
 public function testUnableToParseMesage($message)
 {
     Response::createFromMessage($message);
 }
Example #7
0
 public function handle(Request $request)
 {
     return Response::createFromRequest($request, 'DUMMY!');
 }