phpunit fixture error

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

phpunit fixture error

Post by ratamaster »

Hi, I'm getting an error when I try to call the method get_var() from the class ezSQL_mysql
Inside the setUp method I define $this->db = new ezSQL_mysql; so I guess that the object is reachable over all methods.
But when I execute testTableProject, I get an error on $this->db->get_var:

Fatal error: Call to a member function get_var() on a non-object in C:\AppServ\www\iap\Test\project\Iap\ProjectTest.php on line 43

Code: Select all

 
class tableTest extends PHPUnit_Framework_TestCase
{
 
   protected $db;
    
   
   public function setUp()
   {      
      $this->db = new ezSQL_mysql;
      
      echo $this->db->get_var("SELECT COUNT(*) FROM myTable"); //this works
 
   }
   
   public function tearDown()
   {
        unset($this->db);
   }
 
   
   public function testTableProject()
   {
   
      
      echo $num = $this->db->get_var("SELECT COUNT(*) FROM myTable"); //this is not working
 
      $this->assertEquals(1, $num);
   }
 
}
 
$tableTest = new tableTest();
$tableTest->testTableProject();
 

I'm new with phpunit, maybe I'm doing something wrong.
Thanks in advance
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: phpunit fixture error

Post by VladSun »

You don't have a call to setUp() so $db is empty in testTableProject().
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: phpunit fixture error

Post by arjan.top »

you should run test with phpunit not calling the method directly
ratamaster
Forum Newbie
Posts: 23
Joined: Fri Oct 15, 2004 6:36 am

Re: phpunit fixture error

Post by ratamaster »

arjan.top wrote:you should run test with phpunit not calling the method directly
Thanks, that was the problem :)
Post Reply