InvalidArgumentException:意外值和尾随数据 - Laravel

时间:2016-01-21 10:55:22

标签: php laravel

我使用模型工厂来测试登录页面,但是当我运行测试时,我得到一个无效的参数异常。我的模型工厂:

$factory->define(App\User::class, function (Faker\Generator $faker) {
return [
    'name' => $faker->name,
    'email' => $faker->email,
    'password' => bcrypt(str_random(60)),
    'remember_token' => str_random(100),
    'created_at' => '2016-01-20 11:15:35',
    'updated_at' => '2016-01-20 12:35:15',   
];
});

我的错误信息:

InvalidArgumentException: Unexpected data found.
Unexpected data found.
Unexpected data found.
Unexpected data found.
A two digit minute could not be found
A two digit second could not be found
Trailing data

任何人都知道我哪里出错了?

编辑:

Field           | Type                | Null | Key | Default 
name            | varchar(255)        | NO   |     | NULL
email           | varchar(255)        | NO   | UNI | NULL
password        | varchar(60)         | NO   |     | NULL      
remember_token  | varchar(100)        | YES  |     | NULL      
created_at      | timestamp           | NO   |     | 0000-00-00 00:00:00
updated_at      | timestamp           | NO   |     | 0000-00-00 00:00:00

编辑2:

 public function testLogin()
 {
$user = factory(App\User::class)->create
([
    'email'=>'test@email.com',
    $HashedPassword = Hash::make('password'),
    'password' => $HashedPassword
]);

$this->visit('/login')
    ->type('test@email.com', 'email')
    ->type('password', 'password')
    ->press('Login')
    ->seePageIs('/home');
}

1 个答案:

答案 0 :(得分:1)

尝试:

public function testLogin()
{
    $HashedPassword = Hash::make('password');

    $user = factory(App\User::class)->create
    ([
        'password' => $HashedPassword
    ]);

    $this->visit('/login')
        ->type($user->email, 'email')
        ->type('password', 'password')
        ->press('Login')
        ->seePageIs('/home');
}