laravel - 如何使用 Sentinel 执行 actingAs()

标签 laravel authentication testing laravel-5.1 cartalyst-sentinel

我正在测试需要用户登录的 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/

相关文章:

javascript - Blanket.js vs Istanbul-js vs JSCover

php - 此集合实例上不存在属性 [business_url]

ajax - 使用mongodb在保存()之后获取laravel中最后插入的文档的ID

php - Laravel:分页流畅的查询

ruby-on-rails - 我应该在哪里使用 Devise + RSpec 进行经过身份验证的路由测试?

Laravel 5.6 - 在 Controller 中按名称获取路由

testing - CodenameOne TestRecorder 如何运行测试

php - 向队列中的非注册用户(电子邮件列表)发送邮件

Firefox 扩展 - 在菜单栏中加载页面?

testing - 通过记录和回放方法的调用方式自动生成测试