Closed GrahamCampbell closed 10 years ago
Like i said in #300 i think it may be a good idea to get rid of our integration with Faker directly.
FactoryMuffin::define('User', [
'username' => Faker::string()
])
I don't think that's ever going to work. That sort of syntax would result in the attribute being generated immediately, which is not what we want. We'd have to wrap everything in closures some how, and that's getting way too complex.
Hmm yeah i guess. I just really dislike having to use ;
as separator etc.
Actually, maybe I have a solution, whereby the user isn't directly interacting with faker, technically, but it feels like they are to them:
Syntax in 2.1:
FactoryMuffin::define('Foo', array(
'bar' => 'numberBetween|20;40'
));
Syntax in 3.0:
FactoryMuffin::define('Foo', array(
'bar' => OurFakerFacade::numberBetween(20, 40)
));
So under the hood, we are doing this:
function __call($method, $args)
{
return function () {
return call_user_func_array(array($this->faker, $method), $args);
}
}
I'll implement this whenever I have a min.
I think that is how Factory Girl does it, but I will have to have a look into their code again.
But i like that idea.
I'm working on my "stage 1" refactor right now. It won't change the generic generator for now, but it will massively change the generator classes. I'll sort the faker generator in "stage 2".
Stage 1 is done: https://github.com/thephpleague/factory-muffin/pull/306.
Hmm. The issue with the faker wrapper is that it's hard to handle multiple function calls such as ->unique()->word()
for example.
Actually, I've got this to work. :) I'll push it shortly.
Here can discuss plans and ideas for 3.0.
Refactor The Factory Class
It would be good to abstract the database stuff out of the class.
Callable Generator And Customisation
We currently only allow closures. This will require php 5.4+
TODO...