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

时间:2016-10-16 10:33:02

标签: php laravel-4

我已经完成了Larabook series at Laracasts,但我无法找到解决问题的方法。我的代码在浏览器中完美运行,但我的功能测试失败,因为用户没有登录。这是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方法时,我的所有功能测试都会失败。任何人都可以告诉我为什么它不是登录用户?

1 个答案:

答案 0 :(得分:0)

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

相关问题