I though I would create a CDbTestCase sub class to put code for fixing logging problems and for changing fixtures directory easily:
class DbTestCase extends CDbTestCase
{
// Fixtures sub directory to use
public $directory='';
public function setUp()
{
// Change fixtures directory for all tests
$fixtureManager=$this->getFixtureManager();
$fixtureManager->basePath.=$this->directory;
}
public static function tearDownAfterClass()
{
// Fix for logging not working in tests
Yii::app()->onEndRequest(new CEvent(null));
}
}
But since doing this I have noticed some problems:
-
DbTestCase->fixtures can no longer be used to load fixtures.
-
All fixtures are always loaded anyway, is this right?
EDIT:
I have also now added a setFixtures() method to my DbTestCase class:
class DbTestCase extends CDbTestCase
{
...
public function setFixtures($fixtures)
{
// Set fixtures array
$this->fixtures=$fixtures;
}
...
}
And calling it from my test class:
class ModelTest extends DbTestCase
{
public function setUp()
{
$this->setFixtures(array(
'name'=>'Model'
));
parent::setUp();
}
}
But this doesn’t help either.