Larabook Auth :: check()无效

时间:2016-01-27 10:39:19

标签: php laravel

大家好我有代码问题,
它没有正常工作,我使用所有相同的代码
从头开始有关于larabook的视频 这是我在signUpCept.php中的代码

$I = new FunctionalTester($scenario);
$I->am('a 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',
    'email' => 'john@example.com',
    'password' => 'demo'
]);

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

这是我的RegistrationController.php

class RegistrationController extends \BaseController {

    /**
     * Show a form to register the user.
     *
     * @return Response
     */
    public function create()
    {
        return View::make('registration.create');
    }


    /**
     * Creating a new Larbook user.
     *
     * @return Response
     */
    public function store() 
    {
        $user = User::create(

            Input::only('username', 'email', 'password')

        );

        Auth::login($user);

        return Redirect::home();
    }


}

这就是我得到的错误

Functional Tests (1) ----------------------------------------------------------------------------------------
Sign up for a larabook account (SignUpCept)                                                            Fail
-------------------------------------------------------------------------------------------------------------


Time: 6.04 seconds, Memory: 25.50Mb

There was 1 failure:

---------
1) Failed to sign up for a larabook account in SignUpCept (tests/functional/SignUpCept.php)

 Step  I assert true false
 Fail  Failed asserting that false is true.

Scenario Steps:

 13. $I->assertTrue(false) at tests/functional/SignUpCept.php:28
 12. $I->seeRecord("users",{"username":"JohnDoe","email":"john@example.com","password":"demo"}) at tests/functional/SignUpCept.php:26
 11. $I->see("Welcome to Larabook!") at tests/functional/SignUpCept.php:20
 10. $I->seeCurrentUrlEquals("") at tests/functional/SignUpCept.php:19
 9. $I->click("Sign Up") at tests/functional/SignUpCept.php:17
 8. $I->fillField("Password Confirmation:","demo") at tests/functional/SignUpCept.php:15


FAILURES!
Tests: 1, Assertions: 4, Failures: 1.

1 个答案:

答案 0 :(得分:0)

您无法使用Auth::check(),请注意,您有两个实例,一个用于代码检测,另一个用于正在测试的应用程序。

这意味着您正在尝试Auth::check()进入代码实例,这对您来说无用。

您必须依赖Laravel5模块并使用seeAuthentication()复制您的意图。