doctrine / DoctrineFixturesBundle

Symfony integration for the doctrine/data-fixtures library
MIT License
2.45k stars 202 forks source link

Enhance system to allow only executing some fixtures via an interface #256

Closed noemiquezada closed 5 years ago

noemiquezada commented 5 years ago

This builds off of #255

It's the same idea, but you group your fixtures via an interface instead of tag. The improvement is developer experience, you stay in the Fixture class instead of needing to re-register the service in order to give it the tag.

weaverryan commented 5 years ago

Hey guys!

I'm very happy to see this feature finally re-added / fixed in #255 and #256 :D. After seeing #255, I worked with @noemiquezada to change the implementation detail part. Basically, I think the having this interface is a little bit better DX than a tag. Specifically:

In #256

In #255

services:
    App\DataFixtures\MyFixture:
        - { name: doctrine.fixture.orm, tag: main }

256 basically makes it possible to not need to go into YAML and re-add the service+tag. It's consistent with other places in Symfony.

However, another option is to combine #255 and #256 to allow either the tag approach OR the new interface.

Cheers!

TerjeBr commented 5 years ago

Hi.

I would very much vote for keeping a tag in the service definition as an optional way to group the fixtures. That way you can easily group a whole directory of fixtures with the same group-tag without changing each individual fixture.

alcaeus commented 5 years ago

Apart from feedback above, I believe both approaches to be equally valid: as mentioned before, specifying the groups in the container via a service tag would allow assigning a group to all fixtures from a specific directory, while the solution via an interface causes less configuration overhead. However, I would like to avoid having two different ways to achieve one thing.

Having the groups in the code would be preferable, but I'd also argue that if it's not handled in the container, this should be in doctrine/migrations, not in the bundle.

TerjeBr commented 5 years ago

I think it is one of Symfony's strengths that it does not try to contrain developers to "One True Way". Having more than one way to do things I think is the right thing for symfony, when some developers would prefer one way and others would prefer another way.

I for one, would be very disappointed if I could not have a simple way to group all fixtures that where in the same directory.

Destroy666x commented 5 years ago

I like this approach more since it's possible to easily reuse groups as e.g. consts, so having both would be great.

weaverryan commented 5 years ago

Both approaches have been combined in #260 - and original authors' work + commits were maintained :)