A problem with phpunit and renderpartil

Hi guys.

Please Help.

Testing a class with a function that uses a renderPartial result in a Fatal Error. The class works ok, the problems is not the class. I simplified the case to a very simple testing and the error remains.

The testing is the following

public function testConnection(){

        //conexion testing - here Yii:app works


        $this->assertNotEquals(NULL, $cx);

        //this doesn't work!!

        $text=Yii::app()->controller->renderPartial('ROUTE TO A VIEW', array(),TRUE);


The output window’s text:

PHPUnit 3.4.15 by Sebastian Bergmann.

Fatal error: Call to a member function renderPartial() on a non-object in -THE CLASS FILE(the line with the renderPArtial-

Yii version 1.1.3

IDE netbeans

Some suggest?

What can I do to test a class with a renderPartial?


The error tell you that Yii::app()->controller is not an object. In fact I suppose it doesn’t exist because it must be created when needed, eg when a webuser ask to open an url. This is not because of the renderPartial method.

You should look at the tutorial Functional testing if you want to open an url to test, there is an example like this :

class PostTest extends WebTestCase



    public function testShow()








This is explained at the end of this part of the tutorial.

There is not controller if you are not answering a request.

The problem is in Yii::app()->controller->renderPartial(‘ROUTE TO A VIEW’, array(),TRUE), none instantiated the controller, and so the property Yii::app()->controller does not exists.