/**
  * Make sure that an exception with a error response is wrapped properly.
  *
  * @return void
  */
 public function testSendConnectorException()
 {
     $this->response->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json'));
     $data = ['error_code' => 'ERROR_CODE_1', 'error_messages' => ['Oh dear...', 'Oh no...'], 'correlation_id' => 'corr_id_1'];
     $this->response->expects($this->once())->method('json')->will($this->returnValue($data));
     $exception = new RequestException('Something went terribly wrong', $this->request, $this->response);
     $this->client->expects($this->once())->method('send')->with($this->request)->will($this->throwException($exception));
     $this->setExpectedException('Klarna\\Rest\\Transport\\Exception\\ConnectorException', 'ERROR_CODE_1: Oh dear..., Oh no... (#corr_id_1)');
     $this->object->send($this->request);
 }
示例#2
0
 /**
  * Sends a HTTP request to the specified url.
  *
  * @param string $method  HTTP method, e.g. 'GET'
  * @param string $url     Request destination
  * @param array  $options Request options
  *
  * @throws ConnectorException When the API replies with an error response
  * @throws RequestException   When an error is encountered
  * @throws \LogicException    When Guzzle cannot populate the response
  *
  * @return ResponseValidator
  */
 protected function request($method, $url, array $options = [])
 {
     $request = $this->connector->createRequest($url, $method, $options);
     return new ResponseValidator($this->connector->send($request));
 }