thephpleague / factory-muffin

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

[3.0] [Proposal] Allow callback to determine if a second persist is needed #350

Closed jonsa closed 9 years ago

jonsa commented 9 years ago

I suggest changing Factory::triggerCallback to

private function triggerCallback($object, $model)
{
    if ($callback = Arr::get($this->callbacks, $model)) {
        $saved = $this->isPendingOrSaved($object);
        return $callback($object, $saved) !== false;
    }
    return false;
}

This would allow the second persist to be optional. This was briefly mentioned in #282 but wasn't implemented.

GrahamCampbell commented 9 years ago

Could you send a pull with tests please?