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

randomElement and named relations #973

Closed
pbowyer opened this issue Feb 19, 2019 · 3 comments
Closed

randomElement and named relations #973

pbowyer opened this issue Feb 19, 2019 · 3 comments
Labels
Milestone

Comments

@pbowyer
Copy link

pbowyer commented Feb 19, 2019

Alice has support for picking a random item using the wildcard syntax: @element*. This works great when I've generated fixtures using a loop, ending up with @element1, @element2 ... @elementN.

Where values aren't random (e.g. settings, statuses) and I manually create the fixtures, I give them descriptive names so I can easily reference them in other manually created fixtures. E.g.:

App\Entity\Status:
    success:
        ...
    failure: # Easier to remember than @status2
        ...

But in the generated fixtures, I need to pick a random status.

I have tried:
<randomElement([@success, @failure])>, <randomElement(['@success', '@failure'])>, defining a parameter that's an array of the statuses; all give the error:

Expected argument of type "App\Entity\Setting\Status or null", "Nelmio\Alice\Definition\Value\FixtureReferenceValue" given at property path "status".

Is it possible to pick a random element from a user-defined set?

@theofidry
Copy link
Member

It should be possible, that's a proper bug that needs to be solved

@theofidry theofidry added the Bug label Feb 19, 2019
@theofidry theofidry added this to the 3.x milestone Feb 19, 2019
@pifaace
Copy link

pifaace commented Feb 20, 2019

I confirm, I created a custom provider and a fixture like this :

validationGroup1:
      validationGroupId: 'validationGroup1'
      name: 'sweet validatonGroup1'
      persons: <personCollection([@johnDoe, @janeDoe])>
      orderables: '<orderableCollection([@flyer])>'

and the arg in my personCollection method is an array of "FixtureReferenceValue". It doesn't convert the references to object

@theofidry
Copy link
Member

Closed by #984

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

3 participants