Quote
[03:19:21][root@ps79740:/home/twu5r/public_html/tasker/protected/tests]#phpunit unit/ProjectTest.php
PHPUnit 3.6.12 by Sebastian Bergmann.
Configuration read from /home/twu5r/public_html/tasker/protected/tests/phpunit.xml
Time: 0 seconds, Memory: 11.50Mb
There was 1 error:
1) ProjectTest::testUserAccessBasedOnProjectRole
CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'member-2' for key 'PRIMARY'
/home/twu5r/public_html/dev3/framework/db/CDbCommand.php:354
/home/twu5r/public_html/dev3/framework/db/CDbCommand.php:1181
/home/twu5r/public_html/dev3/framework/web/auth/CDbAuthManager.php:264
/home/twu5r/public_html/tasker/protected/tests/unit/ProjectTest.php:54
FAILURES!
Tests: 6, Assertions: 9, Errors: 1.
PHPUnit 3.6.12 by Sebastian Bergmann.
Configuration read from /home/twu5r/public_html/tasker/protected/tests/phpunit.xml
Time: 0 seconds, Memory: 11.50Mb
There was 1 error:
1) ProjectTest::testUserAccessBasedOnProjectRole
CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'member-2' for key 'PRIMARY'
/home/twu5r/public_html/dev3/framework/db/CDbCommand.php:354
/home/twu5r/public_html/dev3/framework/db/CDbCommand.php:1181
/home/twu5r/public_html/dev3/framework/web/auth/CDbAuthManager.php:264
/home/twu5r/public_html/tasker/protected/tests/unit/ProjectTest.php:54
FAILURES!
Tests: 6, Assertions: 9, Errors: 1.
I (think) have followed everything exactly as per the instructions. (all unit tests previously have passed).
First part of ProjectTest.php:
class ProjectTest extends CDbTestCase { public $fixtures = array( 'projects'=>'Project', 'users'=>'User', 'projUsrAssign'=>':tbl_project_user_assignment', 'projUserRole'=>':tbl_project_user_role', ); 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)); } public function testIsInRole() { $row1 = $this->projUserRole['row1']; Yii::app()->user->setId($row1['user_id']); $project = Project::model()->findByPk($row1['project_id']); $this->assertTrue($project->isUserInRole('member')); } public function testUserAccessBasedOnProjectRole() { $row1 = $this->projUserRole['row1']; Yii::app()->user->setId($row1['user_id']); $project = Project::model()->findByPk($row1['project_id']); //Assign php snippet bizRule $auth = Yii::app()->authManager; $bizRule = 'return isset($params["project"]) && $params["project"]->isUserInRole("member");'; $auth->assign('member', $row1['user_id'], $bizRule); //line 44 $params = array('project'=>$project); $this->assertTrue(Yii::app()->user->checkAccess('updateIssue', $params)); $this->assertTrue(Yii::app()->user->checkAccess('readIssue', $params)); $this->assertFalse(Yii::app()->user->checkAccess('updateProject', $params)); }
My tbl_project_user_role.php file:
<?php return array( 'row1' => array( 'project_id' => 2, 'user_id' => 2, 'role' => 'member', ), ); ?>
Looking at the error, it seems that it's trying to insert a record but that primary key is already been duplicated.
I've tried a couple of things:
- Have the fixtures file return an empty array:
This STILL causes same issue
- Deleted the (only) record from the tbl_project_user_role table
Still get same issue
I am not quite sure what I am missing here?
Any help much appreciated,
gvanto