1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-18 17:10:33 +00:00
Arsse/tests/cases/Db/SQLite3/TestDriver.php

52 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2017-03-08 22:16:35 -05:00
<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
2017-03-08 22:16:35 -05:00
declare(strict_types=1);
2021-04-14 11:17:01 -04:00
2017-12-22 11:41:54 -05:00
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(\JKingWeb\Arsse\Db\SQLite3\Driver::class)]
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
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 09:44:50 -05:00
2019-10-16 14:42:43 -04:00
public static function setUpBeforeClass(): void {
// 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-03-08 22:16:35 -05:00
2019-10-16 14:42:43 -04:00
public static function tearDownAfterClass(): void {
if (static::$interface) {
static::$interface->close();
static::$interface = null;
}
parent::tearDownAfterClass();
@unlink(static::$file);
static::$file = null;
}
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);
}
return true;
}
2017-03-09 17:25:50 -05:00
protected function query(string $q) {
return static::$interface->querySingle($q);
}
2017-08-29 10:50:31 -04:00
}