Like Flask wrote above, use Doctrine DataFixtures.
Save yourself time and avoid Alice Bundle / library. I used it on a project in beginning, but had to remove it soon. You simply do not have enough control over generated data.
- For example you want 3 random players in a team, everything okay, but there is no way to say that they must be unique. At least that was one of the scenarios I had most problems with.
But yes, use faker library.
Another advice that I would give you, implement something like a ->initSeed() method in each of your Fixtures class, which you call at the beginning of the ->load() method. It will call something like this:
$this->faker->seed(100);
Also make your fixtures implement OrderedFixtureInterface, so you have control what is inserted first. Here's the catch... you implement the initSeed() inside load(), NOT inside constructor, because constructor is called in the beginning on all classes, because getOrder() method is needed to find out priority. This way if you add another randomized property at the end of fixture file, the file which comes next, will still generate the same data, so fixture files will not be dependant between themselves.
If you need any code example, let me know, I can help.
Code for saving references:
In the LoadTeamData fixture class, have a constant:
const NUM = 10;
So, you can access it in other fixture file.
When you generate teams in a for loop, use index $i to save the reference.
// Generate teams
for ($i=0; $i<self::NUM; $i++) {
$team = new Team();
// ... set things
$this->setReference('team-'.$i, $team)
$manager->persist($team);
}
$manager->flush();
Then inside LoadPlayerData for example:
// For each team, generate some players
for ($t=0; $t<LoadTeamData::NUM; $t++) {
$team = $this->getReference('team-'.$t);
for ($i=0; $i<self::NUM; $i++) {
$player = new Player($team);
// ... set things
$manager->persist($player);
}
}
$manager->flush();