Exemplo n.º 1
0
 /**
  * Start the server, trigger an exception and see if the logger captured
  * it.
  */
 function testLogException()
 {
     $server = new Server();
     $logger = new MockLogger();
     $server->setLogger($logger);
     // Creating a fake environment to execute http requests in.
     $request = new \Sabre\HTTP\Request('GET', '/not-found', []);
     $response = new \Sabre\HTTP\Response();
     $server->httpRequest = $request;
     $server->httpResponse = $response;
     $server->sapi = new \Sabre\HTTP\SapiMock();
     // Executing the request.
     $server->exec();
     // The request should have triggered a 404 status.
     $this->assertEquals(404, $response->getStatus());
     // We should also see this in the PSR-3 log.
     $this->assertEquals(1, count($logger->logs));
     $logItem = $logger->logs[0];
     $this->assertEquals(\Psr\Log\LogLevel::INFO, $logItem[0]);
     $this->assertInstanceOf('Exception', $logItem[2]['exception']);
 }
Exemplo n.º 2
0
 function handleRequest(RequestInterface $request)
 {
     $sabreRequest = \Sabre\HTTP\Sapi::createFromServerArray($request->getParams());
     $sabreRequest->setBody($request->getStdin());
     if ($sabreRequest->getMethod() === 'POST' && $sabreRequest->getHeader('Content-Type') === 'application/x-www-form-urlencoded') {
         parse_str($sabreRequest->getBodyAsString(), $postData);
         $sabreRequest->setPostData($postData);
     }
     $sabreResponse = new \Sabre\HTTP\Response();
     $this->server->httpRequest = $sabreRequest;
     $this->server->httpResponse = $sabreResponse;
     $this->server->exec();
     $body = $sabreResponse->getBody();
     if (is_scalar($body) || is_null($body)) {
         $newBody = fopen('php://memory', 'r+');
         fwrite($newBody, (string) $body);
         rewind($newBody);
         $body = $newBody;
     }
     // Turning sabre into psr-7 response.
     $psr7Response = new ZendResponse($body, $sabreResponse->getStatus(), $sabreResponse->getHeaders());
     return $psr7Response;
 }