Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faker not returning new randomized data #86

Closed
gbrock opened this issue Mar 16, 2015 · 7 comments
Closed

Faker not returning new randomized data #86

gbrock opened this issue Mar 16, 2015 · 7 comments
Labels

Comments

@gbrock
Copy link

gbrock commented Mar 16, 2015

The following code throws constraint violations on email and username, but works when only 1 row is generated:

$factory('App\User', function($faker) {
    $created = $faker->dateTimeBetween('-2 years', 'now');

    return [
        'username' => $faker->userName,
        'friendly_name' => $faker->firstName,
        'email' => $faker->safeEmail,
        'created_at' => $created,
        'last_login' => $faker->dateTimeBetween($created, 'now'),
    ];
});

Seems like it isn't generating a new value on each faker call...?

@carlosflorencio
Copy link

Yep, the problem is the closure.

Use without the closure and it works.

@h-collector
Copy link

In the meantime, you can use release 2.1

@LasseHaslev
Copy link

+1

@h-collector
Copy link

The problem is actually because of changed design: "Get the generator stuff out of the Factory and Builder classes" as added FactoriesLoader::normalizeDefinitions is resolving user defined Closures only once after loading factories and not before building new entity.

@laurencei
Copy link

+1 - this issue is really annoying.

Is it possible to just call the factory method every time I want to create a user? That way the data is randomised on each call - rather than just once?

i.e. it currently doesnt just affect $faker - it also affects basic PHP functions like rand().

@gbrock
Copy link
Author

gbrock commented Mar 23, 2015

@h-collector's temporary solution works: load 2.1 in your composer.json:

    "laracasts/testdummy": "2.1",

@hootlex
Copy link

hootlex commented Feb 5, 2016

The issue with php functions like rand persists in 2.3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants