1

I use Hautelook AliceBundle which use Faker to generate fixtures with real world data.

In Alice, we can use parameters in our YAML file like below:

parameters:
  pwd_parameter:   anything

My\UserEntity:
  #generate 10 users with password equals to my parameter
  user_{1..10}:
    password:      '<{pwd_parameter}>' 

Is it possible to use parameters to generate dynamic numbers of fixtures?

The solution I am looking for is to do this:

parameters:
  pwd_parameter:   anything
  nb_users:        10

My\UserEntity:
  #generate nb_users users with password equals to my parameter
  user_{1..nb_users}:   #<---THIS IS THE PROBLEM
      password:    '<{pwd_parameter}>

I tried:

user_{1..  nb_users   }
user_{1.. <nb_users>  }
user_{1..<{nb_users}> }
user_{1..<{nb_users}> }

which throws:

Warning: array_merge(): Argument #1 is not an array

How can I generate my number of entities dynamically?

Anthon
  • 69,918
  • 32
  • 186
  • 246
goto
  • 7,908
  • 10
  • 48
  • 58
  • It's configuration, you can't do that. Unless, you create bundle extension to read dynamic bundle parse by your code and put to paramaters – hendrathings Sep 27 '16 at 01:01

1 Answers1

2

It is not possible to do something like that since fixtures yaml configuration files do not get merged with symfony parameters.

Nelmio\Alice\Fixtures\Fixture\RangeName is the class used to validate and parse configuration from your example. Take a look at RangeName::canBuild() and you'll see regular expression that validates yaml key.

You could create your own Builder Method that would randomize number of fixture rows inserted.

Vladimir Cvetic
  • 832
  • 3
  • 8
  • 23
  • Thanks, it put me toward the right direction. Do you know how can I add my custom builder to the existing one? I've seen the `Fixtures\Loader` class but i can't find how to add mine without writing in my vendor class – goto Sep 27 '16 at 11:33
  • The parameters are not symfony one, it is used by alice as you can see in `password: '<{pwd_parameter}>' ` – goto Sep 27 '16 at 11:35
  • Take a look at: https://github.com/nelmio/alice/pull/136/commits someone already created a pull request for it. It's for 1.x but might help you. – Vladimir Cvetic Sep 28 '16 at 07:08