error no teste fixtures

Tenho o seguinte ficheiro unit test:


<?php


class ProjectTest extends CDbTestCase{

    //put your code here

    public $fixtures=array

      (

        'projects'=>'Project'

      );

    

     public function testCreate() 

    { 

      //CREATE a new Project 

      $newProject=new Project; 

      $newProjectName = 'Test Project Creation'; 

      $newProject->setAttributes(array( 

      '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); 

    }

}


?>



no dir tests/fixtures:


<?php


/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */


/**

 * Description of tbl_project

 *

 * @author pc

 */

return array(

  'project1'=>array(

    'name' => 'Test Project 1',

    'description' => 'This is test project 1',

    'create_time' => '',

    'create_user_id' => '',

    'update_time' => '',

    'update_user_id' => '',

  ),

  'project2'=>array(

    'name' => 'Test Project 2',

    'description' => 'This is test project 2',

    'create_time' => '',

    'create_user_id' => '',

    'update_time' => '',

    'update_user_id' => '',

  ),  

  'project3'=>array(

    'name' => 'Test Project 3',

    'description' => 'This is test project 3',

    'create_time' => '',

    'create_user_id' => '',

    'update_time' => '',   'update_user_id' => '',

  ),

);


?>



e adicionei ao test.php o mesmo código que no main mas para uma base de dados clonada chamada trackstar_test:




'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=trackstar_test',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

quando faço run ao ProjectTest.php obtenho o seguinte erro em cada um dos tests:




   CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'



De referir que a primary key está em modo auto_increment então o porquê deste erro?

Obrigado.

Olá,

qual o valor da próxima primary key na tabela?

Se a tabela estiver vazia, execute o seguinte comando MySQL:




ALTER TABLE `banco_dados`.`nome_tabela` AUTO_INCREMENT = 1;



Até mais,

resolvido