首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Sentinel在协同欺骗功能测试中进行身份验证?

如何使用Sentinel在协同欺骗功能测试中进行身份验证?
EN

Stack Overflow用户
提问于 2016-02-03 05:33:02
回答 1查看 193关注 0票数 0

我正在尝试使用协同欺骗来测试laravel应用程序。在Laravel内部,我使用Sentinel进行身份验证。我在内部测试中验证用户时遇到问题。

以下示例均不起作用:

代码语言:javascript
复制
$I->authenticateTestUser($I);
$user = \App\User::where('email','=','test@test.com')->first();
$I->amLoggedAs($user);
$I->canSeeAuthentication();


$credentials = [
    'email'    => 'test@test.com',
    'password' => '****',
];
Sentinel::authenticate($credentials, true);
$I->canSeeAuthentication();


$I->amOnPage('/login');
$I->fillField('email', $email);
$I->fillField('password', $password);
$I->click('Login');
$I->canSeeAuthentication();

如何在协同欺骗功能测试中进行身份验证?

EN

回答 1

Stack Overflow用户

发布于 2016-03-08 02:01:55

您只需在_before方法中使用sentinel:

代码语言:javascript
复制
private $_user;
private $_credentials;

public function _before(FunctionalTester $I)
{
    // we create a user
    $this->_credentials = [
        'last_name'  => 'Test',
        'first_name' => 'test',
        'email'      => 'test@test.fr',
        'password'   => 'password',
    ];
    $this->_user = \Sentinel::register($this->_credentials, true);

    // we log this user
    \Sentinel::authenticate($this->_credentials);
}

您将能够在测试中重用您的用户或凭据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35164185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档