felixele217's avatar

Ignore FormRequests authorize in Test Class

Hey guys,

is there a way how I can ignore the FormRequests authorize()-method while testing. For example my authorize method looks like: (I am using Laravel-permissions from Spatie)

    public function authorize()
    {
        return Auth::user()->can('add entities to site');
    }

And because I am using Spatie, I do not always want to create the necessary permission and assign it to a user in my test and just skip the authorize so that I do not have to do

        $user = parent::signIn();

        $addEntitesPermission = Permission::create(['add entities to site']);

        $user->givePermissionTo($addEntitesPermission);

        $this->post(route('indications.store'), [
            'patients_in_database' => 12391239121231
        ]);

for each test. Is there a way?

Thanks Felix

0 likes
3 replies
Sinnbeck's avatar

You could mock the form request to bypass it. Just google "mock form request laravel" and you should get several tutorials on how to do that

felixele217's avatar

@Sinnbeck thanks, but do I also skip the validation part then? Because I do not want to skip the validation part.

Please or to participate in this conversation.