Skip to content

Instantly share code, notes, and snippets.

@mysiar
Last active October 8, 2019 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mysiar/039508686bdfc04570d8a2a32af6f45f to your computer and use it in GitHub Desktop.
Save mysiar/039508686bdfc04570d8a2a32af6f45f to your computer and use it in GitHub Desktop.
Doctrine Fixtures

Doctrine fixtures in different place than src/DataFixtures

  1. fixtures directory tree (example)

    tests/Fixtures/Data
    tests/Fixtures/Test
    
  2. all fixtures implements FixtureGroupInterface, Data fixtures return data, Test fixtures return test

  3. loading fixtures

    • ./bin/console doctrine:fixtures:load loads all the fixtures
    • ./bin/console doctrine:fixtures:load --group=data loads only data fixtures

To have this working you need to define fixture service for dev environment.

Service file location config/packages/dev/

Service definition service.xml

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <defaults public="false" autoconfigure="true" autowire="true"/>

        <prototype namespace="App\Tests\Fixtures\" resource="../../../tests/Fixtures/*">
            <tag name="doctrine.fixture.orm" />
        </prototype>

    </services>
</container>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment