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
Nov 25, 2022
3
Level 2
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
Please or to participate in this conversation.