function it_maps_declined_response_402_to_payment_result_object(ClientException $exception, Response $response, ResultObjectMapperInterface $resultMapper, MethodInterface $method) { $result = ['error' => 'Error string']; $resultObject = new Payment(); $response->getStatusCode()->willReturn(402); $response->json()->willReturn($result); $method->createResultObject()->willReturn($resultObject); $exception->getResponse()->willReturn($response); $resultMapper->map($result, $resultObject)->shouldBeCalled()->willReturn($resultObject); $this->get($exception, $method)->getResult()->shouldReturn($resultObject); }
function it_performs_request_without_validation(MethodInterface $method, ClientInterface $client, ResultObjectMapperInterface $mapper) { $result = ['amount' => 50.0]; $resultObject = new Payment(); $method->getMethod()->willReturn('GET'); $method->getAction()->willReturn('payment'); $method->getAttributes()->willReturn(['field' => 'value']); $method->createResultObject()->willReturn($resultObject); $mapper->map($result, $resultObject)->shouldBeCalled()->willReturn($resultObject); $client->sendRequest($method, 'GET', 'payment', ['query' => ['field' => 'value']])->shouldBeCalled()->willReturn($result); $this->callNoValidate($method)->shouldReturn($resultObject); }
private function create($class, $exception, MethodInterface $method) { $response = $exception->getResponse()->json(); // map declined response to result object if ($exception->getCode() == 402) { $resultObject = $method->createResultObject(); } else { $resultObject = new Error(); } $response = $this->resultMapper->map($response, $resultObject); return new $class($exception, $response); }