问题
I have a test where I simulate logging in, then afterwards I want to test things as if I was not logged in. Like so.
// log in as user with id 2
$id = 2;
Passport::actingAs(User::findOrFail($id));
testSomeStuff()
...
// now I want to test things as if I was not logged in
Is there a way to do this in one test function? I'm using Laravel 5.6 and Passport 5.
回答1:
Try this in your test
$this->refreshApplication();
Had the same issue and this is the only thing that worked for me
EDIT: It seems to clear out the database also. Calling the logout endpoint directly seems to work too.
$this->actingAs($user)->get('/logout');
来源:https://stackoverflow.com/questions/48979142/how-can-i-simulate-logging-out-after-using-passportactingas-in-a-unit-or-integ