2017-03-09 03:16:35 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-03-09 03:16:35 +00:00
|
|
|
declare(strict_types=1);
|
2017-12-22 16:41:54 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
/**
|
2017-07-20 22:36:03 +00:00
|
|
|
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
|
|
|
|
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
|
2018-11-22 18:55:57 +00:00
|
|
|
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;
|
2017-03-09 14:44:50 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
self::$file = tempnam(sys_get_temp_dir(), 'ook');
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 03:16:35 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
@unlink(self::$file);
|
|
|
|
self::$file = null;
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2018-11-22 18:55:57 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
$this->conf['dbSQLite3File'] = self::$file;
|
|
|
|
parent::setUp();
|
|
|
|
$this->exec("PRAGMA user_version=0");
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
$this->exec("PRAGMA user_version=0");
|
|
|
|
$this->interface->close();
|
|
|
|
unset($this->interface);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
protected function exec(string $q): bool {
|
|
|
|
$this->interface->exec($q);
|
|
|
|
return true;
|
2017-07-08 01:06:38 +00:00
|
|
|
}
|
2017-03-09 22:25:50 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
protected function query(string $q) {
|
|
|
|
return $this->interface->querySingle($q);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 22:25:50 +00:00
|
|
|
|
2018-11-22 18:55:57 +00:00
|
|
|
public function provideDrivers() {
|
2018-11-23 15:01:17 +00:00
|
|
|
self::clearData();
|
2018-11-23 00:55:54 +00:00
|
|
|
self::setConf([
|
2018-11-22 18:55:57 +00:00
|
|
|
'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,
|
|
|
|
],
|
|
|
|
];
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|