thephpleague / factory-muffin

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

3.0 Discussion #295

Closed GrahamCampbell closed 10 years ago

GrahamCampbell commented 10 years ago

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...

scottrobertson commented 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()
])
GrahamCampbell commented 10 years ago

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.

scottrobertson commented 10 years ago

Hmm yeah i guess. I just really dislike having to use ; as separator etc.

GrahamCampbell commented 10 years ago

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.

scottrobertson commented 10 years ago

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.

GrahamCampbell commented 10 years ago

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".

GrahamCampbell commented 10 years ago

Stage 1 is done: https://github.com/thephpleague/factory-muffin/pull/306.

GrahamCampbell commented 10 years ago

Hmm. The issue with the faker wrapper is that it's hard to handle multiple function calls such as ->unique()->word() for example.

GrahamCampbell commented 10 years ago

Actually, I've got this to work. :) I'll push it shortly.