繁体   English   中英

Larabook测试错误 - 无法登录用户

[英]Larabook tests error - cannot login user

我在Laracasts经历了Larabook系列,但我似乎无法找到解决问题的方法。 我的代码在浏览器中完美运行,但我的功能测试失败,因为用户没有登录。这是SignUpTest,它会一直传递到最后一位$I->assertTrue(Auth::check());

$I = new FunctionalTester($scenario);
$I->am('guest');
$I->wantTo('sign up for a Larabook account');

$I->amOnPage('/');
$I->click('Sign Up!');
$I->seeCurrentUrlEquals('/register');

$I->fillfield('Username:', 'JohnDoe');
$I->fillfield('Email:', 'john@example.com');
$I->fillfield('Password:', 'demo');
$I->fillfield('Password Confirmation:', 'demo');
$I->click('Sign Up');

$I->seeCurrentUrlEquals('');
$I->see('Welcome to Larabook');
$I->seeRecord('users', [
    'username' => 'JohnDoe'
]);


$I->assertTrue(Auth::check());

问题是它没有登录用户,因此Auth::check()返回false。 我跟着杰弗瑞去了信,我无法弄清楚为什么它不起作用。

对于SignInCept,我有同样的问题

$I = new FunctionalTester($scenario);
$I->am('a larabook member');
$I->wantTo('login to my larabook account');

$I->signIn();
$I->seeInCurrentUrl('/statuses');
$I->see('Post a status');
$I->assertTrue(Auth::check());

signIn方法

public function signIn()
    {
        $email = 'foo@example.com';
        $username = 'Foobar';
        $password = 'foo';

        $this->haveAnAccount(compact('email', 'username', 'password'));

        $I = $this->getModule('Laravel4');

        $I->amOnPage('/login');
        $I->fillField('email', $email);
        $I->fillField('password', $password);
        $I->click('Sign In');
    }

测试在assertTrue失败,因为它再次获取凭据,甚至转到状态URL,但不知何故用户还没有登录。

每当我调用signIn方法时,我的所有功能测试都会失败。 任何人都可以告诉我为什么它不是登录用户?

问题是默认情况下,在app\\config\\testing\\session.php ,驱动程序设置为array ,这意味着不会发生数据持久性。 因此,解决方案是将其更改为databasecookie或php_doc部分中提供的任何database 在我的情况下,我使用cookie并且我的所有测试都通过了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM