alice icon indicating copy to clipboard operation
alice copied to clipboard

Add the ability to tag & filters out fixtures

Open ogizanagi opened this issue 4 years ago • 5 comments

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?

ogizanagi avatar Jul 16 '20 15:07 ogizanagi

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)

theofidry avatar Aug 14 '20 09:08 theofidry

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

ogizanagi avatar Aug 14 '20 11:08 ogizanagi

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

theofidry avatar Aug 14 '20 12:08 theofidry

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)

ogizanagi avatar Aug 14 '20 13:08 ogizanagi

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 avatar Aug 15 '20 06:08 theofidry