How can I simulate logging out after using Passport::actingAs in a unit or integration test?

我是研究僧i 提交于 2019-12-02 03:22:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!