I just started using this lib and so far so good. But this bug costed me hours. In the docs at the memoize part the example sais:
protected function getDefaults(): array
{
$owner = LazyValue::memoize(fn () => UserFactory::new());
return [
// Call CategoryFactory::random() everytime this factory is instantiated
'category' => LazyValue::new(fn() => CategoryFactory::random()),
// The same User instance will be both added to the Project and set as the Task owner
'project' => ProjectFactory::new(['users' => [$owner]]),
'owner' => $owner,
];
}
but this way it actually creates 2 different User entities. What is should say is:
protected function getDefaults(): array
{
$owner = LazyValue::memoize(fn () => UserFactory::createOne()); // changed ::new() to ::createOne()
return [
// Call CategoryFactory::random() everytime this factory is instantiated
'category' => LazyValue::new(fn() => CategoryFactory::random()),
// The same User instance will be both added to the Project and set as the Task owner
'project' => ProjectFactory::new(['users' => [$owner]]),
'owner' => $owner,
];
}
Hi!
I just started using this lib and so far so good. But this bug costed me hours. In the docs at the memoize part the example sais:
but this way it actually creates 2 different User entities. What is should say is:
this way only 1 User entity is created.