I see you solved this by splitting the tests. I'm trying to test the logout behaviour of Sanctum (api auth). This means that I cannot split my test. My test requires to test this behaviour that seems to be unexpected.
My test does the following:
public function testCanLogout()
{
/** @var User $user */
$user = factory(User::class)->create();
$loginResponse = $this->postJson(route('auth.login'), ['email' => $user->email, 'password' => 'secret']);
$token = $loginResponse['token'];
$authenticatedResponse = $this->getJson(route('auth.current'), ['Authorization' => "Bearer $token"]);
$authenticatedResponse->assertSuccessful();
$authenticatedResponse->assertJsonPath('id', $user->id);
$logoutResponse = $this->postJson(route('auth.logout'), [], ['Authorization' => "Bearer $token"]);
$logoutResponse->assertSuccessful();
$unauthenticatedResponse = $this->getJson(route('auth.current'), ['Authorization' => "Bearer $token"]);
$unauthenticatedResponse->assertStatus(401);
}
Basically, login -> current user -> logout -> current user
The last request does not fail, it returns 200 instead.
After digging a bit, it seems that, as you said, it's not behaving in a stateless manner and thus cannot really test anything.
Does anyone have any idea how to "reset" the authenticated user in the middle of the test?