1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/tests/cases/Db/SQLite3/TestDriver.php
J. King aa1b65b5d4 Take a different tack on shared database tests
Tests for different drivers will have their own files, but all derive
from a common prototype test series where applicable, similar to the
existing arrangement for database function tests. However, the prototype
will reside with other test cases rather than in the library path. The
database function test series will hopefully be moved as well in time.
2018-11-22 13:55:57 -05:00

101 lines
3.2 KiB
PHP

<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
/**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
protected $implementation = "SQLite 3";
protected $create = "CREATE TABLE arsse_test(id integer primary key)";
protected $lock = "BEGIN EXCLUSIVE TRANSACTION";
protected $setVersion = "PRAGMA user_version=#";
protected static $file;
public static function setUpBeforeClass() {
self::$file = tempnam(sys_get_temp_dir(), 'ook');
}
public static function tearDownAfterClass() {
@unlink(self::$file);
self::$file = null;
}
public function setUp() {
$this->conf['dbSQLite3File'] = self::$file;
parent::setUp();
$this->exec("PRAGMA user_version=0");
}
public function tearDown() {
parent::tearDown();
$this->exec("PRAGMA user_version=0");
$this->interface->close();
unset($this->interface);
}
protected function exec(string $q): bool {
$this->interface->exec($q);
return true;
}
protected function query(string $q) {
return $this->interface->querySingle($q);
}
public function provideDrivers() {
$this->clearData();
$this->setConf([
'dbTimeoutExec' => 0.5,
'dbSQLite3Timeout' => 0,
'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'),
]);
$i = $this->provideDbInterfaces();
$d = $this->provideDbDrivers();
$pdoExec = function (string $q) {
$this->interface->exec($q);
return true;
};
$pdoQuery = function (string $q) {
return $this->interface->query($q)->fetchColumn();
};
return [
'SQLite 3' => [
$i['SQLite 3']['interface'],
$d['SQLite 3'],
"CREATE TABLE arsse_test(id integer primary key)",
"BEGIN EXCLUSIVE TRANSACTION",
"PRAGMA user_version=#",
function (string $q) {
$this->interface->exec($q);
return true;
},
function (string $q) {
return $this->interface->querySingle($q);
},
],
'PDO SQLite 3' => [
$i['PDO SQLite 3']['interface'],
$d['PDO SQLite 3'],
"CREATE TABLE arsse_test(id integer primary key)",
"BEGIN EXCLUSIVE TRANSACTION",
"PRAGMA user_version=#",
$pdoExec,
$pdoQuery,
],
'PDO PostgreSQL' => [
$i['PDO PostgreSQL']['interface'],
$d['PDO PostgreSQL'],
"CREATE TABLE arsse_test(id bigserial primary key)",
"BEGIN; LOCK TABLE arsse_test IN EXCLUSIVE MODE NOWAIT",
"UPDATE arsse_meta set value = '#' where key = 'schema_version'",
$pdoExec,
$pdoQuery,
],
];
}
}