1

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');
}
3
  • what is your schema like? Commented Jan 21, 2016 at 13:34
  • that should work. how are you calling your factory? what other errors are you getting? Commented Jan 21, 2016 at 14:49
  • I Just added how I called it and that is the only error I get from that followed by a few paths. Commented Jan 21, 2016 at 15:01

1 Answer 1

1

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');
}
Sign up to request clarification or add additional context in comments.

1 Comment

It got rid of that error but now I get: A request to [localhost/home] failed. Received status code [404]. But thanks for solving the previous one anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.