2

I've created a fixtures loader class in Symfony with custom fakers.

One of this custom functions should return a name from an array of names depending on a non-random value. I'd like this value to be the $current variable when creating a collection of entities with Alice 2.x

As we can do something like this in the fixtures.yml file:

user{1..10}:
  name: someName<current()>

I would like to pass that current value in to my custom function like so:

user{1..10}:
  name: pickFromArray($current)

I've tried $current, current(), , , .... without success.

Thanks!

2 Answers 2

1

You need to use the returned value of <current()> function as parameter. Tested on hautelook/AliceBundle.

user{1..10}: 
  name: <pickFromArray(<current()>)>
0

I don't think you can do that. In my opinion, the best option is pick the name in the Processor:

public function postProcess($object)
{
    if (!$object instanceof User) {
        return false;
    }

    $object->setName($this->pickFromArray($object));

    return true;
}

Where pickFromArray() is a method in your Processor.

2

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.