Yii Framework Forum: A problem with phpunit and renderpartil - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A problem with phpunit and renderpartil Rate Topic: -----

#1 User is offline   iqdavid 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 08-May 09

Posted 28 October 2010 - 06:13 PM

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
        $cx=Yii::app()->db;
        $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?


Thanks
0

#2 User is offline   Parcouss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 12-September 10
  • Location:Toulouse, France

Posted 29 October 2010 - 01:35 AM

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->open('post/1');
        ...
    }
 
    ......
}


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

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 29 October 2010 - 01:50 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users