コード例 #1
0
 public function __construct(Transaction $transaction, Exception $previous = null)
 {
     $this->transaction = $transaction;
     $message = $previous ? $previous->getMessage() : 'Unknown error';
     $status = $previous ? $previous->getCode() : 0;
     if ($error = $transaction->getError()) {
         $message = $error;
     }
     if ($transaction->getResponse() && ($statusCode = $transaction->getResponse()->getStatusCode())) {
         $status = $statusCode;
     }
     parent::__construct($message, $status, $previous);
 }
コード例 #2
0
 /**
  * @param RequestInterface $request
  * @return $this
  * @throws HttpException
  */
 protected function sendViaMock($request)
 {
     $transaction = null;
     try {
         $responseMock = $this->mockRegistry->find($request);
         if (empty($responseMock)) {
             throw new Exception(sprintf('Mock for "%s" has not been found in registry', $request->getUri()));
         }
         $responseBody = $responseMock->getResponse($request);
         $transaction = new Transaction($request, $responseBody);
         if ($transaction->isOK()) {
             return $transaction;
         } else {
             throw new Exception('Response has unsuccessful status');
         }
     } catch (Exception $e) {
         // The following means that request failed completely
         if (empty($transaction)) {
             $transaction = new Transaction($request);
         }
         throw new HttpException($transaction, $e);
     }
 }
コード例 #3
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage JSON Error: Result is empty after parsing
  */
 public function testGetJsonWithEmptyJSON()
 {
     $r = new Transaction(null, "content-type: application/json\n\nnull", 200);
     $r->getJson();
 }