thephpleague / factory-muffin

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

Shouldn't FactoryMuffin::create behave the same as ::instance regarding callback invocation? #418

Closed Bouwdie closed 8 years ago

Bouwdie commented 8 years ago

Persist is currently called before and after the callback invocation. The callback might actually be used by implementations to set required values on the object. Maybe we could even use the ::instance function?

GrahamCampbell commented 8 years ago

Not true. We only call persist if you return a truthy value from the callback indicating your modified it and need to persist the changes to the db.

Bouwdie commented 8 years ago

That is true, but why call persist before the callback has been invoked at all. This causes unnecessary exceptions if you plan to invoke some specific logic in the callback to make your model valid.

GrahamCampbell commented 8 years ago

Because some people were doing things in the callback that needed it saving first.

Bouwdie commented 8 years ago

That scenario would be valid indeed. Situation all clear then :smile: Thx for the fast reply.