我希望有一个人可以帮助我。我安装并尝试使用 phpunit。它运行良好,但现在我尝试使用固定装置和 setUp 方法,但它不起作用。
class RightGroupTest extends CDbTestCase {
public $fixtures = array(
'rights' => 'Right',
'groups' => 'RightGroup',
);
public function setUp() {
$group = new RightGroup($this->groups['group1']);
}
如果我执行上面的测试,我会收到一条错误消息:
例外:类“RightGroupTest”的未知属性“组”。
但是如果我执行这个
class RightGroupTest extends CDbTestCase {
public $fixtures = array(
'rights' => 'Right',
'groups' => 'RightGroup',
);
public function testIndex234() {
$group = new RightGroup($this->groups['group1']);
}
一切正常。
还有第二个问题:
我有一个多对多的关系。例如,我可以创建组,每个组都有几个权限。有没有办法在一个夹具中创建一个包含多个正确对象的组?我已经尝试过这样的事情
return array(
'group1'=>array(
'title'=>'Admin',
'created'=>'2013-05-30',
'updated'=>'2013-05-30',
'rights' => array(
$this->getRecord('right', 'right1'),
$this->getRecord('right', 'right2'),
$this->getRecord('right', 'right3'),
),
),
'group2'=>array(
'title'=>'User',
'created'=>'2013-05-30',
'updated'=>'2013-05-30',
),
);