phpunit

This is my testcase script:


public function testSave()

	{

		// write code here to test post saving method

		Yii::app()->user->setId($this->posts['sample1']['author_id']);

		

		$post = new Post;

		$post->setAttributes($this->posts['sample1'], false);

		$this->assertTrue($post->save(false));

		

		$post = Post::model()->findByPk(1);

		$this->assertTrue($post instanceof Post);

		$this->assertEquals($this->posts('sample1'), $post);

		

	}

i test, output these error(no init.php in fixtures folder):


Integrity constraint violation: 19 PRIMARY KEY must be unique

CDbFixtureManager will truncate corresponding table, why this eror occur.

error log:


2010/09/21 16:31:05 [error] [system.db.CDbCommand] Error in executing SQL: INSERT INTO 'tbl_post' ("title", "content", "status", "create_time", "update_time", "author_id", "tags", "id") VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7). Bind with parameter :yp0='测试帖子1', :yp1='This blog is powered by [Yii framework](http://www.yiiframework.com).', :yp2=2, :yp3=1285057865, :yp4=1285057865, :yp5=1, :yp6='yii, test_one', :yp7=1

In the insert sql statement: id = 1, this is one AUTOINCREMENT filed.(why not null)

I’m sorry my poor english。

Please write in english if you want help in this forum

otherwise post in Chinese subforum

i’m sorry!

As it says primary key must be unique, seems you already have a record with this ID, try to empty the database…

in fact, i empty the table manually, i set id = 2 manually, the error occur still.

(if not empty manually, the CDbFixtureManager will do the same thing).

even though these error occur, fixtures have been inserted into database successfully.

What are the fixtures… could be that here you have duplicate primary key values?

oh, sorry, i insert one fixture into database mistakenly.


$post->setAttributes($this->posts['sample1']

$this->posts[‘sample1’]: item of fixtures!

thanks, mdomba!