rvdlee/doctrine-data-fixture-module

A port for ZF3 of Hounddog's original data-fixture code with the ability to change the executor for fixtures.

0.1.3 2020-04-26 20:13 UTC

README

Latest Version on Packagist Scrutinizer Code Quality Total Downloads GitHub license Donate

Introduction

This is a port for ZF3 of Hounddog's orignal code to make fixtures supported in the form of a CLI command.

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.

$ composer require rvdlee/doctrine-data-fixture-module

Then open config/application.config.php and add DoctrineModule, DoctrineORMModule and DoctrineDataFixtureModule to your modules

Registering Fixtures

To register fixtures with Doctrine module add the fixtures in your configuration.

<?php

return [
    'doctrine' => [
        'fixture' => [
            __NAMESPACE__ . '_fixture' => __DIR__ . '/../src/' . __NAMESPACE__ . '/Fixture',
        ]
    ]
];

Alternativly you can overwrite the executor that fires off the fixtures. I've made an dist file you can follow to make your own. Executors fall in the service category if you need to make a factory for one.

<?php

return [
    'rvdlee' => [
        'doctrine-data-fixture' => [
            'executor' => YourExecutor::class,
        ],
    ],
    'service_manager' => [
        'factories' => [
            YourExecutor::class => YourExecutorFactory::class,
        ],
    ],
];

Usage

Command Line

Access the Doctrine command line as following from your project root:

$ ./vendor/bin/doctrine-module data-fixture:import 

Why use a custom Executor?

I've made fixtures based on entity meta-data or route config for example. A custom executor can provide such information and pass it along to your fixtures.