Hi everyone,
I’m trying to use UnitTesting with yii in order to test some insertions in my comment table.
So the first step i did is to create the CommentTest.php class with the following code:
$comment=new Comment;
$comment->setAttributes(array(
'content'=>'comment 1',
'status'=>1,
'created'=>time(),
'author_id'=>3,
),false);
$this->assertTrue($comment->save(false));
When i execute the test i get the following error message:
1) MessageTest::testApprove
...1452 Cannot add or update a child row: a foreign
key constraint fails (`blogt`.`comment`, CONSTRAINT `FK_comment_user` FOREI
GN KEY (`author_id`) REFERENCES `user` (`id`))
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
But the author_id 3 already exist in my user table. To be sure i have no problem with key constraints, i execute this sql code in a console:
INSERT INTO Comment (content, author_id) VALUES("my first comment",3)
and the insertion succeded with no error.
So the problem is with the yii UnitTesting, and i dont know why and what exactly.
Thanks for helping