I wish to do unit testing for Yii modules separately. I have configured it successfully. But when I run the test class for my module controller(LeadController) following error occurs.
[b]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:
- 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.[/b]
Below is my test class:
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);
}
}
In 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;
}
}
Please help me to solve this issue…