Level 58
The issue might be related to the fact that the test is not clearing the authenticated user between runs. One solution could be to use the refreshApplication method before each test to ensure a clean slate. Here's an example:
public function setUp(): void
{
parent::setUp();
$this->refreshApplication();
}
it('allows a user to edit only their own details', function () {
$user1 = User::factory()->create();
$user2 = User::factory()->create();
actingAs($user1);
expect(get('profile/' . $user2->id))->toHaveStatus(Response::HTTP_FORBIDDEN);
});
Alternatively, you could try using the withoutMiddleware method to disable the auth and verified middleware for this test:
it('allows a user to edit only their own details', function () {
$user1 = User::factory()->create();
$user2 = User::factory()->create();
$this->withoutMiddleware(['auth', 'verified']);
actingAs($user1);
expect(get('profile/' . $user2->id))->toHaveStatus(Response::HTTP_FORBIDDEN);
});