1

I have some PHPUnit test classes which use fixtures. I have for 10 tables fixtures defined. Directory structure:

tests
    fixtures
        table1.php
        ...
        table10.php
    unit
        MyTestClass.php

I now have a test class (MyTestClass.php), in which I only want to populate 2 of these tables. I have the following code in that class.

class BaseACAExportTest extends CDbTestCase
{
    public $fixtures = array(
        'table1' => 'Model1',
        'table2' => 'Model2'
    );

    public function setUp()
    {
        // Call the parent setUp to set up the fixtures
        parent::setUp();
        die();
    }

    public testMe()
    {
        // Test here
    }
}

The function TruncateDatabase is a custom-made helper function which truncates all 10 tables. I have verified that this function works. I run the tests and I inspect after the die statement the database. In it, I see all 10 tables, instead of only the two tables that I have defined in fixtures. Why does it populate all tables defined in the directory fixtures? Is there a way to circumvent this?

physicalattraction
  • 6,485
  • 10
  • 63
  • 122

1 Answers1

0

It's the design of the fixture manager of Yii.

All files in the fixtures folder are used to populate your database.

What you write in the $fixtures property is just the method to more quickly access fixtures data in your tests.

You can circumvent this only by writing your own fixture manager and replacing the default one with it.

hijarian
  • 2,159
  • 1
  • 28
  • 34