示例#1
0
 function it_throws_exception_on_validation_failure(MethodInterface $method, ValidatorInterface $validator, ConstraintViolationList $violations)
 {
     $attributes = ['field' => 'value'];
     $constraints = ['constraints'];
     $method->getValidationConstraints()->shouldBeCalled()->willReturn($constraints);
     $method->getAttributes()->shouldBeCalled()->willReturn($attributes);
     $violations->count()->willReturn(1);
     $violations->__toString()->willReturn('');
     $validator->validate($attributes, $constraints)->willReturn($violations);
     $this->shouldThrow('Cardinity\\Exception\\InvalidAttributeValue')->duringValidate($method);
 }
示例#2
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);
     }
 }
示例#3
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);
 }
示例#4
0
文件: Client.php 项目: web3d/mincart
 /**
  * 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)];
 }