我希望有人能幫助我。我安裝並嘗試使用phpunit。它工作得很好,但現在我試圖使用燈具和setUp方法,它不起作用。Yii:燈具和設置()在單元測試
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']);
}
一切正常。
第二個問題:
我有一個多對多的關係。例如,我可以創建組,每個組都有幾個權限。有沒有辦法在夾具中創建一個包含多個正確對象的組? 我已經嘗試過soomething這樣
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',
),
);
非常感謝。它解決了我的問題。 – EvilKarter