thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Generator returns the same values #425

Closed ihorsamusenko closed 8 years ago

ihorsamusenko commented 8 years ago

I use this code

$f = Faker::instance()->getGenerator();
$fm->define(User::class)->setDefinitions([
        'first_name'   => $f->firstName,
        'last_name' => $f->lastName,
        'email'  => $f->email,
]);

Each time I create new User there are the same values for names and email.

GrahamCampbell commented 8 years ago

Yes. That is because your're using the raw faker there, so it's generating them once when the definition is defined.

GrahamCampbell commented 8 years ago

You need Faker::lastName(). That is not the same as having called instance first.

GrahamCampbell commented 8 years ago

Our version wraps things in closures they get lazy executed later on for each generation.

ihorsamusenko commented 8 years ago

How about adding some @method annotations to League\FactoryMuffin\Faker\Facade? I can do that.