I'm trying to mock a PDO object but am getting an error that reads "PDO::__construct() expects at least 1 parameter, 0 given"
The class that I am mocking is here:
class MockPDO extends PDO
{
public function __construct() {
try
{
$dsn = "mysql:host=localhost;dbname=somedatabase";
parent::__construct($dsn, "root", "root");
}
catch (PDOException $exception)
{
die($exception->getMessage());
}
}
}
My test class is here
class DatabaseTest extends \PHPUnit_Framework_TestCase
{
public function testFindById() {
$pdo = $this->getMock('PDO', array('prepare'));
$stmt = $this->getMock('PDOStatement', array('execute', 'fetch'));
$stmt->expects($this->once())->method('execute')->with($this->equalTo(array(':id' => 2)));
$stmt->expects($this->once())->method('fetch');
$pdo->expects($this->once())->method('prepare')
->with($this->equalTo('SELECT * FROM sometable WHERE id => :id'))
->will($this->returnValue($stmt));
}
I know this is simple, but what am I doing wrong?