1

I'm using Pest PHP (with Laravel) and i'm trying to run test with a given role but i already have 403 status (Forbidden). I'm using spatie/laravel-permission to manage roles.

This is my route :

Route::get('liste', IndexAccessController::class)->name('access.index')->middleware('role:team');

And this is my Pest PHP Test:

beforeEach(function () {
    $me = factory(User::class)->create();
    $role = \Spatie\Permission\Models\Role::where('name', 'team')->first();
    $me->assignRole($role);

    $this->actingAs($me);
});

test('has index page', function () {
    $response = $this->get(route('access.index'));
    $response->assertStatus(200);
});

When I debug to get the user's roles Laravel tells me that he doesn't have any.

Thanks a lot

apokryfos
  • 38,771
  • 9
  • 70
  • 114
julian
  • 95
  • 8
  • 1
    Your code seems fine, i would assume the error is there is no role named team, either by refreshing the db in tests, not seeding the db correctly or not creating a team role in test context. dd($role); would check if that is the problem. – mrhn Sep 10 '20 at 20:42

0 Answers0