Problema di Yii Fixtures?

Mi sembra di avere un problema con i dispositivi in ​​Yii. Il problema sembra essere il seguente,

public $fixtures=arrays('projects'=>'Project'); 

Il model Project esiste e ho le fixture in un nome di file tbl_project.php nella cartella fixtures dei test e il mio nome di tabella si chiama tbl_project. All'interno del file fixtures è il seguente.

 return arrays( 'project1' => arrays( 'name' => 'Test Project 1', 'description' => 'This is test project 1', 'create_time' => '', 'create_user_id' => '', 'update_time' => '', 'update_user_id' => '', ), 'project2' => arrays( 'name' => 'Test Project 2', 'description' => 'This is test project 2', 'create_time' => '', 'create_user_id' => '', 'update_time' => '', 'update_user_id' => '', ), 'project3' => arrays( 'name' => 'Test Project 3', 'description' => 'This is test project 3', 'create_time' => '', 'create_user_id' => '', 'update_time' => '', 'update_user_id' => '', ), ); 

Questo è in realtà dal libro "Agile Web Application Development with Yii". Quando eseguo il test, ottengo quanto segue senza informazioni sui risultati del test.

 PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from ETC/protected/tests/phpunit.xml 

Se rimuovo l'arrays fixtures dalla parte superiore ottengo il seguente.

 Time: 0 seconds, Memory: 9.25Mb There was 1 error: 1) ProjectTest::testRead Exception: Unknown method 'projects' for class 'ProjectTest'. 

Che ovviamente ha un senso. Non so cosa sto facendo male.

  1. Assicurati che la class di test assomigli a questo
 class ProjectTest extends CDbTestCase{ protected $fixtures = arrays( 'projects' => 'Project', ); public function testRead(){ $receivedProject = $this->projects('Project1'); $this->assertTrue($receivedProject instanceof Project); $this->assertEquals($receivedProject->name,'test 1'); } ...` 
  1. Controlla la configuration del dispositivo in protected / config / test.php … Dovrebbe assomigliare …
 ... 'components'=>arrays( 'fixture'=>arrays( 'class'=>'system.test.CDbFixtureManager', ), 'db'=>arrays( 'connectionString' =>'mysql:host=localhost;dbname=your_db_name', 'emulatePrepare' => true, 'username' => 'username', 'password' => 'passwd', 'charset' => 'utf8', ), .... 
  1. Verificare infine le autorizzazioni sul file fixture assicurandosi che possa essere letto

Assicurati inoltre di call il metodo setUp () dei genitori nel tuo setUp ()

 class SomeTest extends CDbTestCase { public $fixtures = arrays( 'somes' => 'Some', ); protected function setUp() { parent::setUp(); // your code.... } // your tests ....................... } 

La tua class di test deriva da CDbTestCase anziché CTestCase?

la tua class di test dovrebbe assomigliare a questa:

 class ProjectTest extends CDbTestCase{ protected $fixtures = arrays( 'projects' => 'Project', ); public function testRead(){ $receivedProject = $this->projects('Project1'); $this->assertTrue($receivedProject instanceof Project); $this->assertEquals($receivedProject->name,'test 1'); } 
 class ProjectTest extends CDbTestCase { public function testCreate() { //CREATE a new Project $newProject=new Project; $newProjectName = 'Test Project Creation'; $newProject->setAttributes(arrays( 'name' => $newProjectName, 'description' => 'This is a test for new project creation', 'createTime' => '2009-09-09 00:00:00', 'createUser' => '1', 'updateTime' => '2009-09-09 00:00:00', 'updateUser' => '1', ) ); $this->assertTrue($newProject->save(false)); //READ back the newly created Project to ensure the creation worked $retrievedProject=Project::model()->findByPk($newProject->id); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals($newProjectName,$retrievedProject->name); } public function testRead() { $retrievedProject = $this->projects('project1'); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals('Test Project 1',$retrievedProject->name); } public function testUpdate() { $project = $this->projects('project2'); $updatedProjectName = 'Updated Test Project 2'; $project->name = $updatedProjectName; $this->assertTrue($project->save(false)); //read back the record again to ensure the update worked $updatedProject=Project::model()->findByPk($project->id); $this->assertTrue($updatedProject instanceof Project); $this->assertEquals($updatedProjectName,$updatedProject->name); } public function testDelete() { $project = $this->projects('project2'); $savedProjectId = $project->id; $this->assertTrue($project->delete()); $deletedProject=Project::model()->findByPk($savedProjectId); $this->assertEquals(NULL,$deletedProject); } public function testGetUserOptions() { $project = $this->projects('project1'); $options = $project->userOptions; $this->assertTrue(is_arrays($options)); $this->assertTrue(count($options) > 0); } public $fixtures=arrays( 'projects'=>'Project', 'users'=>'User', 'projUsrAssign'=>':tbl_project_user_assignment', ); } 

assicurati che l'installazione venga fornita con i suoi genitori

 <i>public function setUp() { parent::setUp(); }</i>