after the mocking object PDO as follows:
class AdProvidersTest extends PHPUnit_Framework_TestCase { public function dataProvider() { $providers = array ( array (1, '1st', 'desc_1', 101), array (2, '2nd', 'desc_2', 202), array (3, '3rd', 'desc_3', 303) ); return $providers; } public function testAdProviders_getConnection($id, $name, $desc, $account_id) { $data = array ( array ( 'id' => $id, 'name' => $name, 'desc' => $desc, 'account_id' => $account_id, ) ); $stmt = $this->getMock('PDOStatement', array ('execute','fetchAll')); $stmt->expects($this->any()) ->method('execute') ->will($this->returnValue(true)); $stmt->expects($this->any()) ->method('fetchAll') ->will($this->returnValue($data)); $pdo = $this->getMock('PDO', array('prepare'), array('sqlite:dbname=:memory'),'PDOMock_' . uniqid(),true); $pdo->expects($this->any()) ->method('prepare') ->will($this->returnValue($stmt)); } }
I want to test the connection using this function:
function getDbh() { if ($this->db === null){ $this->db = Slim::getInstance()->db; } return $this->db->getConnection(); }
but after setting up the database using pdo mock, I get this error when trying to get a connection:
PHP Fatal error: Call to undefined method AdProvidersTest::getMockConnection() in /home/al/adserver/adserver/test/classes/AdProvidersTest.php on line 48
is there any way to add this getConnection function to the mocked PDO?