1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 17:12:41 +00:00
Arsse/tests/cases/Db/SQLite3/TestDriver.php

102 lines
3.2 KiB
PHP
Raw Normal View History

2017-03-09 03:16:35 +00:00
<?php
/** @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 */
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
public static function setUpBeforeClass() {
self::$file = tempnam(sys_get_temp_dir(), 'ook');
}
2017-03-09 03:16:35 +00:00
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;
}
2017-03-09 22:25:50 +00:00
protected function query(string $q) {
return $this->interface->querySingle($q);
}
2017-03-09 22:25:50 +00:00
public function provideDrivers() {
$this->clearData();
2018-11-23 00:55:54 +00:00
self::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,
],
];
}
2017-08-29 14:50:31 +00:00
}