我正在测试需要用户登录的 Laravel 5.1 页面。我的项目使用 Cartalyst/Sentinel 包进行身份验证。
我试过了,但我无法识别用户是否已登录。
public function testPageWithLogin()
{
$user = Sentinel::findById(2);
$this->actingAs($user)
->withSession([])
->visit('/page')
->dontSee('Whoops')
->dontSee('login');
}
我该怎么做才能让用户被视为已登录?
最佳答案
我忘记使用 Sentinel::login 方法登录用户。用户是合法的,只是未被视为已登录。
这是应该的方式。
public function testPageWithLogin()
{
$user = Sentinel::findById(2);
Sentinel::login($user);
$this->actingAs($user)
->withSession([])
->visit('/page')
->dontSee('Whoops')
->dontSee('login');
}
关于laravel - 如何使用 Sentinel 执行 actingAs(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37085017/