Page 1 of 1

phpunit fixture error

Posted: Wed Jul 15, 2009 10:22 pm
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

Re: phpunit fixture error

Posted: Thu Jul 16, 2009 3:49 am
by VladSun
You don't have a call to setUp() so $db is empty in testTableProject().

Re: phpunit fixture error

Posted: Thu Jul 16, 2009 4:20 am
by arjan.top
you should run test with phpunit not calling the method directly

Re: phpunit fixture error

Posted: Thu Jul 16, 2009 10:29 am
by ratamaster
arjan.top wrote:you should run test with phpunit not calling the method directly
Thanks, that was the problem :)