api-skeletons/doctrine-data-fixture 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

api-skeletons/doctrine-data-fixture

最新稳定版本:6.0.8

Composer 安装命令:

composer require api-skeletons/doctrine-data-fixture

包简介

Doctrine Data Fixtures with Grouping for Laminas

README 文档

README

Build status Gitter Patreon Total Downloads

This provides command line support for Doctrine Fixtures in Laminas. Often projects will have multiple sets of fixtures for different object managers or modules such as from a 3rd party API. When this is the case a tool which can run fixtures in groups is needed. Additionally dependency injection must be available to the fixtures. To accomplish these needs this module uses a Service Manager configurable on a per-group basis.

Releases

The 6.x release tags support PHP 7.2 and above.

Installation

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

$ composer require api-skeletons/doctrine-data-fixture

Add this module to your application's configuration:

'modules' => [
   ...
   'ApiSkeletons\Doctrine\DataFixture',
],

laminas-component-installer

If you use laminas-component-installer, that plugin will install doctrine-data-fixture as a module for you.

Configuration

This module builds on top of Doctrine configuration. The configuration in a module which implements fixtures is:

return [
    'doctrine' => [
        'fixture' => [
            'group1' => [
                'object_manager' => 'doctrine.entitymanager.orm_default',
                'executor' => Executor::class,
                'purger' => Purger::class,
                'invokables' => [
                    'ModuleName\Fixture\FixtureOne' => 'ModuleName\Fixture\FixtureOne',
                ],
                'factories' => [
                    'ModuleName\Fixture\FixtureTwo' => 'ModuleName\Fixture\FixtureTwoFactory',
                ]
            ],
            'group2' => [
                'object_manager' => 'doctrine.entitymanager.orm_zf_doctrine_audit',
                ...
            ],
        ],
    ],
];

Each group is a Laminas ServiceManager configuration. This allows complete dependency injection control of your fixtures.

The 'executor' and 'purger' keys are optional and allow for custom classes for these functions. If omitted the Doctrine ORM classes will be used.

Listing Fixtures

index.php data-fixture:list [<group>]

List all object managers and their groups, list all groups for a given object manager, or specify object manager and group to list all fixtures for a group.

Executing Fixtures from Command Line

index.php data-fixture:import <group> [--purge-with-truncate] [--do-not-append]

The <group> is required.

Append is the default option. This is inversed with the new --do-not-append

Options:

--purge-with-truncate if specified will purge the object manager's tables before running fixtures.

--do-not-append will delete all data in the database before running fixtures.

Executing Fixtures from Code

For unit testing or other times you must run your fixtures from within code you must fetch the DataFixtureManager with build and pass the group name to the service manager then load the fixtures into the Loader manually.

use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use ApiSkeletons\Doctrine\DataFixture\Loader;

// Run audit fixtures
$dataFixtureManager = $application->getServiceManager()
    ->build('ApiSkeletons\Doctrine\DataFixture\DataFixtureManager', ['group' => 'group-name']);

$loader = new Loader($dataFixtureManager);
$purger = new ORMPurger();
$executor = new ORMExecutor($auditEntityManager, $purger);

foreach ($dataFixtureManager->getAll() as $fixture) {
    $loader->addFixture($fixture);
}

$executor->execute($loader->getFixtures(), true);

Getting Help

index.php data-fixture:help

Important Notes

  • You can only run one group at a time from the command line. If you need to run more create a script to run them in sequence.
  • The ServiceManager is injected into each DataFixtureManager at getServiceLocator() so you can use instantiators which run from that level. This makes the DataFixtureManager work like a plugin manager defined with $serviceListener->addServiceManager().
  • You cannot use abstract factories. Each fixture must be individually configured.

统计信息

  • 总下载量: 36.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-09