如何使用doctrine fixture清除添加的记录

时间:2014-12-21 11:50:23

标签: unit-testing symfony doctrine-orm

我在执行每个测试之前使用DoctrineFixturesBundle创建测试记录。但它在我的数据库中造成了混乱,因此我想在每次测试完成后删除这些添加的记录。如何在不删除整个数据库的情况下执行此操作?

   /**
     * Function initializing test environment
     */
    protected function setUp()
    {
        //
        // set the client object for easier access (and cleaner code)
        //
        $this->client = static::createClient();

        //
        // create database fixtures
        //
        $container = $this->client->getContainer();
        $doctrine = $container->get('doctrine');
        $entityManager = $doctrine->getManager();

        $userFixture = new LoadUsersData();
        $userFixture->load($entityManager);
    }

    /**
     * Function that runs when the testing is finished
     */
    public function tearDown()
    {
        parent::tearDown();

        //
        // purge database fixtures
        //


        //
        // close database connection
        //
        $this->em->close();
    }

0 个答案:

没有答案