einblick/odm-fixtures-test-case

一个WebTestCase,可以自动执行传递的包名中的ODM Fixtures。

0.1 2012-12-04 14:04 UTC

This package is not auto-updated.

Last update: 2024-09-14 12:27:39 UTC


README

Build Status

一个TestCase基类(扩展WebTestCase),可以从传递的包名中自动加载和清除ODM Fixtures。

VERSION: Compatible for Symfony2 version >= 2.1.*

安装

Composer

将以下依赖项添加到项目的composer.json文件中:

"require": {
    # ..
    "einblick/odm-fixtures-test-case": "dev-master"
    # ..
}

文档

简单使用示例

<?php
namespace My\Namespace\Tests;

/**
 * Import the FixtureTestCase class
 */
use Einblick\ODMFixturesTestCase\Test\FixtureTestCase;

/**
 * This test will load ODM Fixtures from Bundles
 */
class MyODMFixtureLoadingTest extends FixtureTestCase
{
    /**
     * Pass the bundles you want to load the fixtures from
     *
     * @var array
     */
    public $fixtures = array(
        'MySuperBundle',
        'AnotherSuperBundle'
    );

    /**
     * Use it!
     */
    protected function setUp()
    {
        $options = array(

           // The document manager's service id
           'document_manager'  => 'doctrine.odm.mongodb.document_manager', // default

           // The directory structure inside the bundles where to look for Fixtures
           'default_directory' => '/DataFixtures/MongoDB' // default

       );

        $kernelOptions = array(
            // Same options as to WebTestCase::createKernel()
        );

        $this->loadFixtures($options, $kernelOptions);
    }

    /**
     * Don't forget to tearDown parent in overridden tearDown methods
     */
    protected function tearDown()
    {
        parent::tearDown();
    }
}