Unexpected Behavior Of Cdbfixturemanager::getrecord()

Hi,

the result of the CDbFixtureManager::getRecord() depends on the place of its first call. I’m not sure, so let’s discuss if this is the expected behavior.

Here is an example:

class MyTestCase extends CDbTestCase {

public $fixture = array(‘my_table’ => ‘MyTable’);

public function testMyTestOne() {

// get fixture record BEFORE changing the db


// this is calling $this->getFixtureManager()->getRecord('my_table', array('myFxiture'))


$fix_before = $this->my_table('myFixture');





$model = new MyTable();


$model->attr = 'foo';


$model->save();





// this is true, as expected


$this->assertNotEquals($fix_before, $model);

}

public function testMyTestTwo() {

$model = new MyTable();


$model->attr = 'foo';


$model->save();





// get fixture record AFTER changing the db


// this is calling $this->getFixtureManager()->getRecord('my_table', array('myFxiture'))


$fix_after = $this->my_table('myFixture');





// this is NOT true, i didn't expect this


$this->assertNotEquals($fix_after, $model);

}

public function testMyTestThree() {

// get fixture record BEFORE changing the db


// this is calling $this->getFixtureManager()->getRecord('my_table', array('myFxiture'))


$fix_before = $this->my_table('myFixture');





$model = new MyTable();


$model->attr = 'foo';


$model->save();





// get fixture record a second time after changing the db


// this is calling $this->getFixtureManager()->getRecord('my_table', array('myFxiture'))


$fix_after = $this->my_table('myFixture');





// this is true, as expected


$this->assertNotEquals($fix_before, $model);





// this is true, as expected


// because we called getRecord() the first time before we changed the db


$this->assertNotEquals($fix_after, $model);

}

}

The getRecord() method is creating the CActiveRecord object with $model->findByPk($pk), the first time it is called.

What do u think? Is that behavior expected?

I think getRecord() should always return the data of the fixture file.

Or it should always return the data from the db.

But it is strange returning always the data of the db, from the time of first calling the method.