我希望單獨對Yii模塊進行單元測試。我已成功配置它。但是當我運行我的模塊控制器(LeadController)的測試類時發生以下錯誤。Yii模塊的單元測試
PHPUnit 3.7.31 by Sebastian Bergmann.
Configuration read from D:\xampp\htdocs\AdlugeCore\protected\modules\lead\tests\ phpunit.xml
E
Time: 153 ms, Memory: 3.00Mb
There was 1 error:
1) LeadTest::testActionAdd Trying to get property of non-object
D:\xampp\htdocs\AdlugeCore\protected\modules\lead\controllers\LeadController.php :57 D:\xampp\htdocs\AdlugeCore\protected\modules\lead\tests\unit\LeadTest.php:15
FAILURES! Tests: 1, Assertions: 0, Errors: 1.
下面是我的測試類:
Yii::import('application.protected.modules.lead.controllers.*');
Yii::import('application.protected.modules.lead.components.*');
class LeadTest extends CTestCase {
public $obj;
public function setUp() {
$this->obj = new LeadController(rand());
$this->obj->init();
}
public function testActionAdd() {
$this->obj->actionAdd();
$this->assertTrue(TRUE);
}
public function tearDown() {
unset($this->obj);
}
}
在LeadController.php
class LeadController extends Controller {
public $lead;
public function init() {
$this->lead = new LeadManager();
}
public function actionAdd($param = array()) {
$result = $this->lead->AddProcess($param);
return $result;
}
}
請幫我解決這個問題...
錯誤位於D:\ xampp \ htdocs \ AdlugeCore \ protected \ modules \ lead \ controllers \ LeadController.php的第57行,那麼您可以添加該錯誤嗎? – topher
$ result = $ this-> lead-> AddProcess($ param); 它在上面給出... –
你可以在'$ result = $ this-> lead-> AddProcess($ param)''之前''var_dump($ this-> lead)'' – topher