I’m having problems on pages 191-194. I am getting the following error when trying to run % phpunit unit/ProjectTest.php on page 195.
FAILURES!
Tests: 6, Assertions: 13, Errors: 1.
[root@localhost tests]# vim ../models/Project.php
[root@localhost tests]# phpunit unit/ProjectTest.php
PHPUnit 3.5.11 by Sebastian Bergmann.
.....E
Time: 1 second, Memory: 14.00Mb
There was 1 error:
1) ProjectTest::testUserRoleAssignment
CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null
/var/www/html/yii/framework/db/CDbCommand.php:338
/var/www/html/yii/trackstar/protected/models/Project.php:117
/var/www/html/yii/trackstar/protected/tests/unit/ProjectTest.php:71
FAILURES!
Tests: 6, Assertions: 13, Errors: 1.
I have made sure the table tbl_project_user_role is empty in addition i don’t believe I have any typos in either the Project.php model or the ProjectTest.php test case. Here they are
public function associateUserToRole()
{
$sql = "INSERT into tbl_project_user_role(project_id,user_id,role) VALUES(:projectId,:userId,:role)";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId", $this->id, PDO::PARAM_INT);
$command->bindValue(":userId",$userId, PDO::PARAM_INT);
$command->bindValue(":role",$role, PDO::PARAM_STR);
return $command->execute();
}
public function removeUserFromRole()
{
$sql = "DELETE from tbl_project_user_role where project_id=:projectID and user_id=:userId AND role=:role";
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId",$this->id,PDO::PARAM_INT);
$command->bindValue(":userId",$userId,PDO::PARAM_INT);
$command->bindValue(":role",$role,PDO::PARAM_STR);
return $command->execute();
}
public function testUserRoleAssignment()
{
$project = $this->projects('project1');
$user = $this->users('user1');
$this->assertEquals(1,$project->associateUserToRole('owner',$user->id));
$this->assertEquals(1,$project->removeUserFromRole('owner',$user->id));
}
I’m at a road block. Your help would be greatly appreciated