Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to tag & filters out fixtures #1043

Open
ogizanagi opened this issue Jul 16, 2020 · 5 comments
Open

Add the ability to tag & filters out fixtures #1043

ogizanagi opened this issue Jul 16, 2020 · 5 comments
Labels

Comments

@ogizanagi
Copy link
Contributor

ogizanagi commented Jul 16, 2020

Given the following fixtures:

return [
    Fluid::class => [
        'Fluid 01' => [
            'usableInPrimaryCircuit' => true,
        ],
        'Fluid 02' => [
            'usableInPrimaryCircuit' => false,
        ],
    ],
    Circuit::class => [
        'Circuit 01' => [
            'number' => 1,
            'fluid' => '@Fluid *',
        ],
    ]
];

I'd like to be able to filter out the fluids used to generate a circuit when using @Fluid *, as some can not be used on a primary circuit (and the model would throw a domain exception).

An idea would be to add the ability to "tag" fixtures as well as filtering using a flag. Something like:

return [
    Fluid::class => [
        'Fluid 01 (tags usableInPrimaryCircuit)' => [
            'usableInPrimaryCircuit' => true,
        ],
        'Fluid 02' => [
            'usableInPrimaryCircuit' => false,
        ],
    ],
    Circuit::class => [
        'Circuit 01' => [
            'number' => 1,
            'fluid' => '@Fluid * (tags usableInPrimaryCircuit)',
        ],
    ]
];

When used in a fixture name, tags allows to add tags to it.
When used in a property/call argument/…, it allows to filter out the available fixtures for a pattern.

Note: It cannot be workaround by changing the fixture name (for instance NonUsableFluidInPrimaryCircuit 02) because I need the names to be formed the same way to reference them. Hence the suggestion to add something like tag capabilities (which would be more flexible as well).

What do you think?

@theofidry
Copy link
Member

It's an idea, but I'm a bit concerned about the complexity of this feature while I think it would be a lot easier with #998.

That said I think it's somewhat doable at the moment with a faker provider -> you can pass all the fluids to it and then filter them out (but relying on the object state instead of alice's tags)

@ogizanagi
Copy link
Contributor Author

🤔 Hmm, but how could the faker provider be aware of the fluids populated by Alice?

@theofidry
Copy link
Member

I don't remember if @fluid* would pass all the fluid instances or only one 🤔

@ogizanagi
Copy link
Contributor Author

ogizanagi commented Aug 14, 2020

No actually, as in the examples above, it'll pass a single random fluid instance.
But indeed perhaps a new syntax to allow injecting all objects matching a pattern in a faker provider would be simpler and flexible enough? (even allowing to access the whole objects set would do it I guess)

@theofidry
Copy link
Member

But indeed perhaps a new syntax to allow injecting all objects matching a pattern in a faker provider would be simpler and flexible enough? (even allowing to access the whole objects set would do it I guess)

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants