在单元测试或集成测试中使用Passport :: actingAs后,如何模拟注销? [英] How can I simulate logging out after using Passport::actingAs in a unit or integration test?

查看:91
本文介绍了在单元测试或集成测试中使用Passport :: actingAs后,如何模拟注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模拟登录的测试,然后我要像未登录一样对事物进行测试.

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

有一种方法可以在一个测试功能中执行此操作吗?我正在使用Laravel 5.6和Passport 5.

Is there a way to do this in one test function? I'm using Laravel 5.6 and Passport 5.

推荐答案

在测试中尝试一下

$this->refreshApplication();

有同样的问题,这是唯一对我有用的事情

Had the same issue and this is the only thing that worked for me

似乎也清除了数据库.直接调用注销端点似乎也可以.

It seems to clear out the database also. Calling the logout endpoint directly seems to work too.

$this->actingAs($user)->get('/logout');

这篇关于在单元测试或集成测试中使用Passport :: actingAs后,如何模拟注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆