29 throw new \Exception(
'You must set the $driver public property');
35 $this->markTestSkipped($this->driver .
' was not enabled, not correctly configured or of the wrong version');
42 switch ($this->driver) {
45 $pdo =
new PDO(SABRE_MYSQLDSN, SABRE_MYSQLUSER, SABRE_MYSQLPASS);
48 $pdo = new \PDO(
'sqlite:' . SABRE_TEMPDIR .
'/testdb');
51 $pdo = new \PDO(SABRE_PGSQLDSN);
52 $version =
$pdo->query(
'SELECT VERSION()')->fetchColumn();
53 preg_match(
'|([0-9\.]){5,}|',
$version, $matches);
55 if (version_compare(
$version,
'9.5.0',
'<')) {
57 $this->markTestSkipped(
'We require at least Postgres 9.5. This server is running ' .
$version);
64 $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
68 $this->markTestSkipped($this->driver .
' was not enabled or not correctly configured. Error message: ' . $e->getMessage());
84 return $this->
getDb();
98 $queries = file_get_contents(
99 __DIR__ .
'/../../../examples/sql/' . $this->driver .
'.' . $schemaName .
'.sql' 102 foreach (explode(
';', $queries) as
$query) {
104 if (trim($query) ===
'') {
122 $tableNames = (array)$tableNames;
123 $db = $this->
getDb();
124 foreach ($tableNames as $tableName) {
125 $db->exec(
'DROP TABLE IF EXISTS ' . $tableName);
133 switch ($this->driver) {
138 unlink(SABRE_TEMPDIR .
'/testdb');
dropTables($tableNames)
Drops tables, if they exist.
createSchema($schemaName)
Uses .sql files from the examples directory to initialize the database.
getDb()
Returns a fully configured PDO object.