dev3cplusnow's avatar

phpspec - test laravel validation

Hi guys, I'm trying to test the eloquent validation. For this I create a base model where there is a method named validateAndSave, which constructs the validation rules. My model extends from this class and is initialized in the repository. When I try to test this method there's an error with the Validator::make facade. How I could test the validation rules of the model using phpspec?

0 likes
2 replies
foxted's avatar

Can we see come code? An error message?

dev3cplusnow's avatar
public function validateAndSave(array $options = array())
{

    $validator = $this->makeValidator($options, $this->rules);
    $this->intervalSave($options, true, $validator);
}


protected function makeValidator(array $options = array(), $rules = array())
{
    $this->attributes = array_merge($this->attributes, $options);

    return $validator = Validator::make(
        $this->attributes, $rules
    );
}

when I do $this->shouldThrow('FailedValidationExceptions')->duringValidateAndSave() I got "call make() on a non object"

Please or to participate in this conversation.