Yii Framework Forum: Unexpected Behavior Of Cdbfixturemanager::getrecord() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Unexpected Behavior Of Cdbfixturemanager::getrecord() Rate Topic: -----

#1 User is offline   fschindler 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-November 13

Posted 14 November 2013 - 06:20 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users