Ad

InvalidArgumentException: Unexpected Value And Trailing Data - Laravel

- 1 answer

I'm using a model factory to test a login page but when I run the test I get an Invalid Argument Exception. My Model Factory:

$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',   
];
});

And my error message:

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

Anyone know where I went wrong?

Edit:

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

Edit 2:

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

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

Answer

try:

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');
}
Ad
source: stackoverflow.com
Ad