after mocking PDO object like this:
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;
}
/**
* @dataProvider dataProvider
*/
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 the pdo mock i get this error when trying to get the connection:
PHP Fatal error: Call to undefined method AdProvidersTest::getMockConnection() in /home/al/adserver/adserver/test/classes/AdProvidersTest.php on line 48
is there a way to add this getConnection
function to the mocked PDO?
Your error message states that line 48 in AdProvidersTest.php
is calling the method getMockConnection()
in the class AdProvidersTest
and that you have not defined the method getMockConnection()
in class AdProvidersTest
Does this help you narrow in on your answer?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With