alice icon indicating copy to clipboard operation
alice copied to clipboard

Indexed arrays no longer work in Alice 3.x

Open majermi4 opened this issue 5 years ago • 3 comments

Hello, our company has used Alice for fixture generation for a long time now we have a lot of complex fixtures in our project and we utilized parsing of indexed arrays to data formatters of our custom data fakers in Alice 2.x.

With the upgrade to Alice 3.x, however, this is no longer possible and passing of indexed arrays leads to internal token strings being given to the data fakers.

Example fixture file: Screenshot 2019-06-20 at 08 16 38

Results in value given to data faker: Screenshot 2019-06-20 at 08 21 03

I would like to ask if whether it is a bug in the new Alice version or if it was never meant to work this way and happened to work by chance in Alice 2.x. If that was the case, does anybody know of a clean way to passing indexed arrays to data fakers?

Thank you for answers and for a great library! Michal.

majermi4 avatar Jun 20 '19 06:06 majermi4

If that worked in 2.x it was pure luck :) I think a way to do it would be:

data: <dynamicObjectData(<(["property1" => intval(1)])>)>

Not sure that it will work though :/ It might be easier to just put everything in the faker provider directly.

theofidry avatar Jun 20 '19 06:06 theofidry

@theofidry: Thank you for the fast reply.

I tried the format you recommended and it works only with a small adjustment when you take away space around the "=>".

So this works: <dynamicObjectData(<(["property1"=>intval(1)])>)>

It is a bit cumbersome to use and if there was a chance at some point, it would be great if alice supported indexed arrays by default.

For simple cases, it would be ok to put everything in a faker directly, however, in the scale of what we're building, it is unfortunately not maintainable to create custom logic for each different scenario.

Thank you, Mike.

majermi4 avatar Jun 20 '19 06:06 majermi4

I think a more viable long term plan would be https://github.com/nelmio/alice/issues/601#issuecomment-481601779.

theofidry avatar Jun 20 '19 07:06 theofidry