alice
alice copied to clipboard
Add the ability to tag & filters out fixtures
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?
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)
🤔 Hmm, but how could the faker provider be aware of the fluids populated by Alice?
I don't remember if @fluid*
would pass all the fluid instances or only one 🤔
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)
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)
👍