Summer Sale! All accounts are 50% off this week.

vincent15000's avatar

assert not working

Hello,

I have this test.

public function test_member_can_see_the_dashboard(): void
{
    $user = User::where('pseudo', 'member')->first();

    $response = $this->actingAs($user)->get('dashboard');

    $response->assertStatus(200);
}

I have seeded the database with test datas, the member user exists, but it cannot access the dashboard.

It should be able to access the dashboard.

That means that there is something wrong in my test.

But I really don't understand what could be wrong.

Any idea ?

Thanks a lot ;).

V

0 likes
7 replies
Nakov's avatar

You say the database is seeded, are you using the same database for your tests? That does not make sense if that's the case.. And there will be error in your console that should give you hints on what is going wrong. Just by looking at the code no one can tell what's wrong.

1 like
vincent15000's avatar

@Nakov I have seeded the test database, so it's ok for the database.

I have changed with this and it works.

        $response = $this->actingAs($user)->view('dashboard');

        $response->assertSee('Liste des adhésions');

For me it has no sense because the test seems to tell that a member cannot access to the dashboard, but with the last code, it can see the dashboard page.

Strange ...

vincent15000's avatar

@Nakov Here is the route.

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('dashboard', DashboardController::class)->name('dashboard');
});

By writing this, I wonder if it's not the verified middleware that generates the error.

Is it possible to deactivate a specific middleware while testing ?

I have tested this, but it doesn't work better.

$response = $this->actingAs($user)->withoutMiddleware('verified')->get('dashboard');

And if I remove the middleware from the route definition, it works.

Nakov's avatar
Nakov
Best Answer
Level 73

@vincent15000 when you are seeding the users table you can set the value for email_verified_at column and then you don't need to think about the middleware again.

1 like

Please or to participate in this conversation.