.init.php fixtures

I have a table Currency, it’s just a large table with data that never changes, certainly not by any activity on the website.

User has fk to Currency.

So I wrote tests/fixtures/currency.init.php to avoid having the FixtureManager truncate the table.

Am I suppose to return any value from this .init.php file? Some kind of $rows, some kind of fetchAll kind of thing?

I haven’t been able to find anything in the docs or books about this, nor have I seen it mentioned in the forum.

There are no hard and fast requirements for this script, other than it be a valid PHP script. The framework code is simply looking for a file of a specified name, and if that file exists, it requires it, otherwise, it will truncate the table:


if(is_file($initFile))

        require($initFile);

    else

        $this->truncateTable($tableName);

So, even simply having an open PHP script tag and nothing else in this file will successfully prevent the table truncation.

If you don’t need this data to be reset to a known state before every test, can I ask why you want to use a fixture for it?

Protecting it from being truncated by the fixture manager. Turns out my User didn’t have to declare the Currency as fixture, it still showed up.

We are using two db connections in our app, requiring two fixture manager extensions and two CDbTestCase extensions and so on.

It’s early in the project, only two people are at all familiar with Yii at this point, and neither one of those people is me :blink:

The files used for confg, as in config/main.php, all return an array(); I was wondering if these .init.php files needed to return something in that fashion.

Hey, keep Austin weird.