Du behøver ikke at håne PDO. Her er et eksempel på, hvordan det virker:
ConnectionTest.php:
<?php
class ConnectionTest extends PHPUnit_Extensions_Database_TestCase
{
public function getConnection()
{
$database = 'myguestbook';
$user = 'root';
$password = '';
$pdo = new PDO('mysql:host=localhost;dbname=myguestbook', $user, $password);
$pdo->exec('CREATE TABLE IF NOT EXISTS guestbook (id int, content text, user text, created text)');
return $this->createDefaultDBConnection($pdo, $database);
}
public function getDataSet()
{
return $this->createFlatXMLDataSet(__DIR__.'/dataSets/myFlatXmlFixture.xml');
}
public function testGetRowCount()
{
$this->assertEquals(2, $this->getConnection()->getRowCount('guestbook'));
}
}
myFlatXmlFixture.xml
<?xml version="1.0" ?>
<dataset>
<guestbook id="1" content="Hello buddy!" user="joe" created="2010-04-24 17:15:23" />
<guestbook id="2" content="I like it!" user="nancy" created="2010-04-26 12:14:20" />
</dataset>
Resultat:
PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
.
Time: 215 ms, Memory: 5.25Mb
OK (1 test, 1 assertion)
Hovedpointen i test mod db er ikke at håne db, men også skabe absolut samme PDO-forbindelse ikke til produktions-db, men til db for test, det kan være mysql, sqlite osv...