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); }
/** * Checks whether the given value is a valid URL that may probably be safely used as a redirect url. * * @param string $value URL to validate * * @return boolean true if the url is correct */ protected function isValidRedirectUrl($value) { $validator = Validation::createValidator(); $constraints = array(new Constraints\Type(array('type' => 'string')), new Constraints\Length(array('min' => $this->getParameter('min_length', 10), 'max' => $this->getParameter('max_length', 1000))), new Constraints\Url(array('protocols' => $this->getParameter('allowed_protocols', array('http', 'https'))))); if ($this->getParameter('check_base_href', true)) { $constraints[] = new Constraints\Callback(array('methods' => array(array($this, 'hasCorrectBaseHref')))); } $violations = new ConstraintViolationList(); foreach ($constraints as $constraint) { $violations->addAll($validator->validateValue($value, $constraint)); } if ($violations->count() === 0) { return true; } else { $this->getContext()->getLoggerManager()->logTo('default', \AgaviLogger::WARNING, __METHOD__, $violations->__toString()); return false; } }
function let(ConstraintViolationList $violations) { $violations->__toString()->willReturn($this->violation); $this->beConstructedWith('Message', $violations); }