miaou-corp/fixture-loader-bundle 问题修复 & 功能扩展

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

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

miaou-corp/fixture-loader-bundle

Composer 安装命令:

composer require miaou-corp/fixture-loader-bundle

包简介

Manage Nelmio Alice fixtures with Doctrine.

README 文档

README

This bundle use Nelmio/Alice for fixture generation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

$ composer require --dev miaou-corp/fixture-loader-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require --dev miaou-corp/fixture-loader-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        //...
        
        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            //...
            $bundles[] = new Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle();
            $bundles[] = new MiaouCorp\Bundle\FixtureLoaderBundle\MiaouCorpFixtureLoaderBundle();
        }
    }

    // ...
}

Step 3: Configure the bundle

# config_test.yml

# Do not use production database !
# SQLite in memory is recommended for tests speed.
doctrine:
    dbal:
        url: 'sqlite:///:memory:'

miaoucorp_fixture_loader:
    # This is where you fixture files are stored.
    directory: /path/to/directory # Default to: '%kernel.project_dir%/tests/Resources/fixtures'

Important note: Each time you load a fixture file, the database schema is drop and rebuilt, so do not use in production...

Usage

Inside a WebTestCase:

$client = static::createClient();

// You might want to do this if you do multiple request on a single test
// As kernel is rebooted on each request, so your database and fixtures will be lost.
$client->disableReboot();

// Or static::$kernel->getContainer for a KernelTestCase
$client->getContainer()->get('miaoucorp.fixture_loader')->loadFile('my-fixture-file.yaml');

$client->request('GET', '/some-path');

// To keep some fixture in memory for later use:
// Where "user_1" is the fixture key.
$fixtures = $client->getContainer()->get('miaoucorp.fixture_loader')
    ->loadFile('my-fixture-file.yaml', ['user_1']);
    
$userId = $fixtures['user_1']->getId();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固