Php 在单元测试或集成测试中使用Passport::actingAs后,如何模拟注销?

Php 在单元测试或集成测试中使用Passport::actingAs后,如何模拟注销?,php,laravel,laravel-5.5,laravel-passport,Php,Laravel,Laravel 5.5,Laravel Passport,我有一个模拟登录的测试,然后我想测试一下,就好像我没有登录一样。像这样 // 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。在您的测试中尝试此功能

我有一个模拟登录的测试,然后我想测试一下,就好像我没有登录一样。像这样

// 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。

在您的测试中尝试此功能

$this->refreshApplication();
有同样的问题,这是唯一对我有用的东西

编辑:它似乎也清除了数据库。直接调用注销端点似乎也能起作用

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

以下工作将起作用:

Auth::logout();

不要设置
使用light\Support\Facades\Auth在您的测试类之上。

也许可以尝试
Auth::logout()
?您找到解决方案了吗?我也有同样的问题。获取错误:方法Illumb\Auth\RequestGuard::注销不存在。@Shadrix我想我不存在。