Hi guys,
I followed both the latest Test Dummy and SQLite in memory lessons and tried to implement an integration test for a user repository to make sure every thing works as planned.
To start off, here's the migration for the table.
$table->increments('id');
$table->char('username', 32)->unique();
$table->char('password', 64);
$table->char('remember_token', 128)->nullable();
$table->nullableTimestamps(); //For SQLite
I found an error with the timestamps not working and fixed that no problem but when I run my tests with Test Dummy using the times(int); method I'll get the following error
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: users.id (SQL: insert into "users" ("id", "username", "password", "updated_at", "created_at") values (267, ztorp, y$hpDQnOccwaMElFt8j3YUAu1RrqMmCs6NJPR.1VyjeZbNZ21TGTBwS, 2014-12-24 11:21:45, 2014-12-24 11:21:45))
And here is the factory for Users:
$factory('User', [
'id' => $faker->randomNumber(),
'username' => $faker->userName,
'password' => Hash::make($faker->word)
]);
And finally the test that the error comes from:
Factory::times(5)->create('User');
$users = $this->repo->getAllUsers();
$this->assertInternalType('array', $users);
$this->assertCount(5, $users);
I've tried to ensure that the user.id field is unique by playing around a lot with the id field of the User factory for Test Dummy but with little to no luck.
Whilst it makes the real test fail, the error doesn't appear when removing the times method, repeating create() over and over will still produce the error.
The tests work perfectly when running MySQL but for the sake of improving the speed of the tests I'd like to get the SQLite memory database working correctly.
Any ideas guys?