public $viewId=null;
public $viewData=null;
/*
* Override of render to enable unit testing of controller
* */
public function render($view,$data=null,$return=false)
{
$this->viewId = $view;
$this->viewData = $data;
/* if the component 'fixture' is defined we are probably in the test environment */
if(!Yii::app()->hasComponent('fixture')){
parent::render($view,$data,$return);
}
}
and my test is a bit different
class reviewTest extends CDbTestCase
{
public $fixtures=array(
'post'=>'Post'
);
public function setUp() {
// Import controller
Yii::import('application.controllers.*');
}
public function testIndex() {
$controller = new ReviewController('review');
$this->assertTrue($controller!=null);
$this->assertInstanceOf('ReviewController', $controller);
$controller->actionIndex();
$this->assertTrue($controller->model!=null);
$this->assertEquals('index', $controller->viewId);
}
}
I’ve disabled the render() in the Test environment because I was only trying to debug the controller and also because it was giving me a lots of errors, but the next step will be enable again the render() and create a property to store the html output ready to be validated.