lundi 25 décembre 2017

Laravel testing form requests prepareValidation method

I have a form request, where I need to replace some values inside the prepareValidation method. At the moment my tests for form requests look like:

public function testAttributeIsChoiceAndNeedsOptions()
    {
        $atts = [
            'type' => 'choice',
        ];
        $validator = Validator::make($atts, $this->rules);
        $this->assertArrayHasKey('options', $validator->messages()->toArray());
    }

In this case the prepareValidation method is never called. (If you wonder there are the rules come from, they are initialised in the setUp method

$this->rules = new StoreAttributeRequest()->rules();

)

I already tried the following to trigger the prepareValidation method:

$myRequest->getValidatorInstance()->validate()

Unfortunately this results in an exception: Call to a member function make() on null

Any thoughts or better ways to test the prepareValidation method?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire