nelmio / alice

Expressive fixtures generator
MIT License
2.5k stars 329 forks source link

Fixtures groups #271

Open soullivaneuh opened 9 years ago

soullivaneuh commented 9 years ago

The idea is to be able to set group label on fixtures files or properties in order to filter which fixtures need to be loaded.

Sample: My project has statistics sections that require a lot of fixtures to make it reliable. But loading those fixtures take a lot of time and I don't need it all the time.

Passing those one on a group named stats for sample will permit to filter when I want to load it, or not.

It's globally the same than behat feature group goal.

theofidry commented 8 years ago

@Soullivaneuh do you have any proposal on the syntax?

ErikJson commented 8 years ago

Would love to have something very similar for customizing fixtures based on the current application environment. So I would name the groups "testing", "development", etc and pass in the desired environment as a filter of sort.

theofidry commented 8 years ago

We could probably add a flag group <group name>. That being said, I'm not found of encouraging the practice of having fixture groups depending of the environment. It encourages having super bug set of fixtures to do everything, including functional tests, which leads to very unmaintainable fixtures. It's much easier to empty the database and load only a set of fixture dedicated to a specific scenario instead.

ErikJson commented 8 years ago

Good point regarding the tests, and it made me rethink that part of our fixture usage. We are still left with the need to separate the "base" and "development" though.

So, for example; we always want to create the admin user no matter what the environment is. But sometimes we also want a bunch of dummy users for development purposes. I am currently struggling a lot to accommodate this while at the same time not repeating template definitions between files, and I think that this group concept would be of great help.

theofidry commented 8 years ago

What framework are you using? We solved this in Symfony with HautelookAliceBundle by having fixtures in different directories. The Bundle is able to locate the fixtures to which we can pass such groups. It can easily be applied in other frameworks as well.

ErikJson commented 8 years ago

We are using a customized framework built on Lumen (with Doctrine). For better and for worse, but at least we are in full control :)

We already have a solution in place where we can group our fixtures using directories that allows them to be applied separately, but code reuse gets very complex and we end up with duplicated template definitions. The group feature would hopefully allow us to put everything related to an entity in a single file.

theofidry commented 8 years ago

One thing I didn't mention is that besides having directories, we also have data loaders. They're kind of a legacy of the previous system which was supporting another bundle, but they still remain helpful when it comes down to try to load the same files for different environments.

theofidry commented 8 years ago

One tricky thing would be how to handle templates: would child templates inherit of this flag? If not what if you refer to a template which does not have this flag? Throw an error?

soullivaneuh commented 8 years ago

@Soullivaneuh do you have any proposal on the syntax?

Why not simply like phpunit does ? https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.groups

theofidry commented 8 years ago

@Soullivaneuh not sure to see what you mean, could you provide a sample?

theofidry commented 8 years ago

ping @Soullivaneuh