thephpleague / factory-muffin

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

Callable Save vs string #397

Closed jdgriffith closed 9 years ago

jdgriffith commented 9 years ago

Is it possible to set the save method to a Closure? I was doing this in a previous version and it worked pretty well. I am trying to save models to a mongo instance. I was able to set the callable maker but could not find the same functionality with the save.

GrahamCampbell commented 9 years ago

Is it possible to set the save method to a Closure?

Hmmm, no.

GrahamCampbell commented 9 years ago

We decided to remove that ability in 3.0. Instead, we recommend you use a custom ModelStore class.

GrahamCampbell commented 9 years ago

Just pass your custom instance as the first param when constructing a factory muffin object.

jdgriffith commented 9 years ago

Well bum. I didn't follow your last comment. Do you have an example?

GrahamCampbell commented 9 years ago

Extend our model store class, override the stuff you want changing, then when you do new FactoryMuffin(), instead do new FactoryMuffin(new YourStoreClass()).

jdgriffith commented 9 years ago

Ok thanks.

GrahamCampbell commented 9 years ago

We decided that was a better way to do things than have a hacky override using closures. :)

jdgriffith commented 9 years ago

I do not see the Model Store class you are referencing. Are you referencing the Definition class?

GrahamCampbell commented 9 years ago

https://github.com/thephpleague/factory-muffin/blob/master/src/ModelStore.php

jdgriffith commented 9 years ago

Perfect! Much less hacky and OO. I must be on a different version. Will check my composer file. Thanks for all the responses!

GrahamCampbell commented 9 years ago

If your using v2, then you can use a closure to customize stuff. See https://github.com/thephpleague/factory-muffin/tree/2.1#additional-customisation.

jdgriffith commented 9 years ago

Ya, that's what I was doing before in v2. Honestly, I was hoping the groups and definitions were a little better in v3. It appears you can set a group off of a definition but can't search for all models belonging to a group. I suppose I could code that easily though.