phpsymfonydoctrine

Error in doctrine/doctrine-fixtures-bundle 3.7.0: Too few arguments to function Doctrine\Common\DataFixtures\AbstractFixture::getReference()


After composer update updated my doctrine/doctrine-fixtures-bundle to v3.7.0 and doctrine/data-fixtures to v2.0.0, I'm getting this error when trying to load my fixtures:

In AbstractFixture.php line 78:
Too few arguments to function Doctrine\Common\DataFixtures\AbstractFixture::getReference(), 1 passed in ... and exactly 2 expected

See my own answer below.


Solution

  • Solution

    At the reported line, add a second parameter to getReference() with the class of the referenced object (i.e. not the Fixtures class), e.g.:

    $this->getReference('testuser', User::class);
    

    Background

    The change was introduced in https://github.com/doctrine/data-fixtures/pull/464, and released in doctrine/data-fixtures 2.0.0

    And doctrine/doctrine-fixtures-bundle 3.7.0 added support for doctrine/data-fixtures 2.0.0.

    So if you don't have doctrine/data-fixtures explicitly mentioned in your composer.json, you got it automatically upgraded to v2.0.0.

    So, to prevent surprises like this in the future, add this to your composer.json:

    "doctrine/data-fixtures": "^2.0",