laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
457 stars 80 forks source link

rand() always returns the same value in a $factory function #72

Closed naimkhalifa closed 9 years ago

naimkhalifa commented 9 years ago

Considering the following code in my factories.php file:

$factory('App\Event', [

'title' => $faker->sentence(8),
'user_id' => rand(1,10),
'description' => $faker->sentence,
'address' => $faker->address,
'date' => $faker->date,
'time' => $faker->time

]);

When I do 'php artisan db:seed' , I get the same integer value for all events table entries on 'user_id'.

naimkhalifa commented 9 years ago

Ok, there is an easy workaround with faker:

'user_id' => $faker->randomDigitNotNull