示例#1
0
 protected function useResponse(Request $request, Response $response, $filter = null)
 {
     if ($request->isExpectingResult()) {
         $this->serializer->expects($this->once())->method($response->getType() === MessageTypes::ERROR ? 'serializeError' : 'serializeResult')->with($request->getMethodName(), $this->equalTo($response->getResultBody(), 0, 0), $response->getHeaders()->get('content-type'))->will($this->returnValue($response->getResultBody()));
     } else {
         $this->serializer->expects($this->never())->method('serializeResult');
     }
     if (!$filter) {
         $filter = function () {
         };
     }
     $this->transport->expects($this->once())->method('sendResponse')->with($response)->will($this->returnCallback($filter));
 }
示例#2
0
 private function createResponse($type, $result, Response $response, Request $request)
 {
     $response->setType($type);
     $this->forwardHeaders($request, $response);
     if (!MessageTypes::isResponseTypeWithResult($type)) {
         return $response;
     }
     if ($type === MessageTypes::ERROR) {
         if ($result instanceof \Exception) {
             ExceptionChanger::clean($result);
         }
         $resultBody = $this->serializer->serializeError($request->getMethodName(), $result, $response->getHeaders()->get('content-type'));
     } else {
         $resultBody = $this->serializer->serializeResult($request->getMethodName(), $result, $response->getHeaders()->get('content-type'));
     }
     $response->setResultBody($resultBody);
     return $response;
 }