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); }
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); } }
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); }
/** * 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)]; }