Reputation: 169
So I am trying to do some database testing in phpunit, and when trying to connect to the database, i get this error:
Fatal error: Class 'PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection' not found in D:\xampp\php\pear\PHPUnit\Extensions\Database\TestCase.php on line 145
I opened up testcase.php and checked line 145. This is line 143-146:
protected function createDefaultDBConnection(PDO $connection, $schema = '')
{
return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($connection, $schema);
}
Also, heres the getConnection function i used, incase something is wrong with it:
public function getConnection() {
if ($this->conn === null) {
try {
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$this->conn = $this->createDefaultDBConnection($pdo, 'test');
} catch (PDOException $e) {
echo $e->getMessage();
}
}
return $this->conn;
}
Upvotes: 1
Views: 364
Reputation: 157967
You need to install the Database extension. Issue the following commands in the console:
sudo pear config-set auto_discover 1
sudo pear install --alldeps pear.phpunit.de/DbUnit
(On Windows you need to omit the sudo
and probably locate the path to pear.exe)
Upvotes: 1