1

I am trying to create test data using the Alice Bundle fixtures in my Symfony2 project. So far I've been pretty successful. But now I am trying to create fixtures from two entities that depend on each other.

Here is my fixture definition for the entity "account":

Bundle\CoreBundle\Entity\Account:
account{1..10}:
    isBadDebt: <numberBetween(1, 2)>
    primaryOrganization: @organization<current()>

Now, here is my fixture definition for the entity "organization":

Bundle\CoreBundle\Entity\Organization:
organization (template):
    organizationName: <company()>
    firstName: <firstName()>
    lastName: <lastName()>
    billingLine1: <streetAddress()>
    billingLine2: 15%? <secondaryAddress()>
    billingCity: <city()>
    billingState: <stateAbbr()>
    billingZip: <postcode()>

organization{1..10} (extends organization):
    account: @account<current()>

If I remove the line: primaryOrganization: @organization<current()> from the account.yml file, everything works fine. 10 account fixtures are created, and 10 organization fixtures are created. The organizations are aware of the accounts because they have been defined. But if I try to set the primary organization in the account fixture, it complains because the organizations have not yet been defined.

Is there any way to get both fixtures to depend on each other?

kc_rob
  • 147
  • 1
  • 9

1 Answers1

0

It turns out if I combine these two definitions in one file, the two entities will be aware of each other.

If anyone knows a solution to the separate files as originally posted, that would be helpful, but this is an appropriate work around.

kc_rob
  • 147
  • 1
  • 9
  • I know this is years later, but they do provide docs on including files: https://github.com/nelmio/alice/blob/2.x/doc/fixtures-refactoring.md#including-files and say: "All files are merged in one data set before generation, and the includer's content takes precedence over included files' fixtures in case of duplicate keys." – Beyerz Jan 17 '19 at 09:14