Ejemplo n.º 1
0
 function it_does_not_validate_method_with_no_constraints(MethodInterface $method, ValidatorInterface $validator)
 {
     $constraints = [];
     $method->getValidationConstraints()->shouldBeCalled()->willReturn($constraints);
     $validator->validate([], $constraints)->shouldNotBeCalled();
     $this->validate($method);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 public function validate(MethodInterface $method)
 {
     $constraints = $method->getValidationConstraints();
     if (empty($constraints)) {
         return;
     }
     $violations = $this->validator->validate($method->getAttributes(), $constraints);
     if (count($violations) !== 0) {
         throw new Exception\InvalidAttributeValue('Your method contains invalid attribute value', $violations);
     }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
0
 /**
  * Prepare request options for particular method
  * @param MethodInterface $method
  * @return array
  */
 private function getOptions(MethodInterface $method)
 {
     if ($method->getMethod() == $method::GET) {
         return ['query' => $method->getAttributes()];
     }
     return ['headers' => ['Content-Type' => 'application/json'], 'body' => json_encode($this->prepareAttributes($method->getAttributes()), JSON_FORCE_OBJECT)];
 }