Esempio n. 1
0
 function it_accepts_a_command_object_in_lieu_of_an_input_array(FactoryInterface $validatorFactory, ValidatorInterface $validator)
 {
     $formDataAsCommand = new CommandStub();
     $formDataCastToArray = get_class_vars(get_class($formDataAsCommand));
     $validatorFactory->make($formDataCastToArray, $this->getValidationRules(), [])->willReturn($validator);
     $this->validate($formDataAsCommand)->shouldReturn(true);
 }
 /**
  * Validate the form data
  *
  * @param array $formData
  * @return mixed
  * @throws FormValidationException
  */
 public function validate(array $formData)
 {
     $this->validation = $this->validator->make($formData, $this->getValidationRules(), $this->getValidationMessages());
     if ($this->validation->fails()) {
         throw new FormValidationException('Validation failed', $this->getValidationErrors());
     }
     return true;
 }
 function it_throws_an_exception_for_invalid_form_data(FactoryInterface $validatorFactory, ValidatorInterface $validator)
 {
     $fakeFormData = ['username' => ''];
     $validatorFactory->make($fakeFormData, $this->getValidationRules(), [])->willReturn($validator);
     $validator->fails()->willReturn(true);
     $validator->errors()->willReturn([]);
     $this->shouldThrow('Laracasts\\Validation\\FormValidationException')->duringValidate($fakeFormData);
 }