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 {
|
2018-11-27 19:26:33 +00:00
|
|
|
protected static $implementation = "SQLite 3";
|
2018-11-22 18:55:57 +00:00
|
|
|
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() {
|
2018-11-27 19:26:33 +00:00
|
|
|
// create a temporary database file rather than using a memory database
|
|
|
|
// some tests require one connection to block another, so a memory database is not suitable
|
|
|
|
static::$file = tempnam(sys_get_temp_dir(), 'ook');
|
|
|
|
static::$conf['dbSQLite3File'] = static::$file;
|
|
|
|
parent::setUpBeforeclass();
|
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() {
|
2018-12-10 18:17:04 +00:00
|
|
|
static::$interface->close();
|
|
|
|
static::$interface = null;
|
2018-11-27 19:26:33 +00:00
|
|
|
parent::tearDownAfterClass();
|
|
|
|
@unlink(static::$file);
|
|
|
|
static::$file = null;
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-03-09 21:36:33 +00:00
|
|
|
|
2018-11-27 19:26:33 +00:00
|
|
|
protected function exec($q): bool {
|
|
|
|
// SQLite's implementation coincidentally matches PDO's, but we reproduce it here for correctness' sake
|
|
|
|
$q = (!is_array($q)) ? [$q] : $q;
|
|
|
|
foreach ($q as $query) {
|
|
|
|
static::$interface->exec((string) $query);
|
|
|
|
}
|
2018-11-22 18:55:57 +00:00
|
|
|
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) {
|
2018-11-27 19:26:33 +00:00
|
|
|
return static::$interface->querySingle($q);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|