Unit Testing For Yii Modules

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


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.[/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());



public function testActionAdd() {




public function tearDown() {




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…

Ouch! testing controllers with unit tests? Not a great idea, as PHPUnit won’t be able to initialise the whole server environment used to correctly replicate and test everything.

If I were you I’d cover them with functional tests if possible.

Leave Unit Tests to Models and Libraries.

Thank you for your replay… I will try to do functional testing…