mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 05:44:53 +00:00
More test coverage tweaks
This commit is contained in:
parent
d3bca6eb47
commit
70f76f77fa
5 changed files with 27 additions and 10 deletions
|
@ -12,7 +12,9 @@ abstract class AbstractDriver implements Driver {
|
||||||
protected abstract function lock(): bool;
|
protected abstract function lock(): bool;
|
||||||
protected abstract function unlock(bool $rollback = false) : bool;
|
protected abstract function unlock(bool $rollback = false) : bool;
|
||||||
|
|
||||||
|
/** @codeCoverageIgnore */
|
||||||
public function schemaVersion(): int {
|
public function schemaVersion(): int {
|
||||||
|
// FIXME: generic schemaVersion() will need to be covered for database engines other than SQLite
|
||||||
try {
|
try {
|
||||||
return (int) $this->query("SELECT value from arsse_meta where key is schema_version")->getValue();
|
return (int) $this->query("SELECT value from arsse_meta where key is schema_version")->getValue();
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
|
|
|
@ -59,9 +59,7 @@ class Statement extends \JKingWeb\Arsse\Db\AbstractStatement {
|
||||||
$a += $this->bindValues($value, $a);
|
$a += $this->bindValues($value, $a);
|
||||||
} else if(array_key_exists($a,$this->types)) {
|
} else if(array_key_exists($a,$this->types)) {
|
||||||
// if the parameter type is something other than the known values, this is an error
|
// if the parameter type is something other than the known values, this is an error
|
||||||
if(!array_key_exists($this->types[$a], self::BINDINGS)) {
|
assert(array_key_exists($this->types[$a], self::BINDINGS), new Exception("paramTypeUnknown", $this->types[$a]));
|
||||||
throw new Exception("paramTypeUnknown", $this->types[$a]);
|
|
||||||
}
|
|
||||||
// if the parameter type is null or the value is null (and the type is nullable), just bind null
|
// if the parameter type is null or the value is null (and the type is nullable), just bind null
|
||||||
if($this->types[$a]=="null" || ($this->isNullable[$a] && is_null($value))) {
|
if($this->types[$a]=="null" || ($this->isNullable[$a] && is_null($value))) {
|
||||||
$this->st->bindValue($a+1, null, \SQLITE3_NULL);
|
$this->st->bindValue($a+1, null, \SQLITE3_NULL);
|
||||||
|
|
|
@ -39,10 +39,10 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
|
||||||
function testIterateOverResults() {
|
function testIterateOverResults() {
|
||||||
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
|
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
|
||||||
$rows = [];
|
$rows = [];
|
||||||
foreach(new Db\SQLite3\Result($set) as $row) {
|
foreach(new Db\SQLite3\Result($set) as $index => $row) {
|
||||||
$rows[] = $row['col'];
|
$rows[$index] = $row['col'];
|
||||||
}
|
}
|
||||||
$this->assertEquals([1,2,3], $rows);
|
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testIterateOverResultsTwice() {
|
function testIterateOverResultsTwice() {
|
||||||
|
|
|
@ -16,18 +16,20 @@ class TestDbUpdateSQLite3 extends Test\AbstractTest {
|
||||||
const MINIMAL1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
|
const MINIMAL1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
|
||||||
const MINIMAL2 = "pragma user_version=2";
|
const MINIMAL2 = "pragma user_version=2";
|
||||||
|
|
||||||
function setUp() {
|
function setUp(Conf $conf = null) {
|
||||||
if(!extension_loaded("sqlite3")) {
|
if(!extension_loaded("sqlite3")) {
|
||||||
$this->markTestSkipped("SQLite extension not loaded");
|
$this->markTestSkipped("SQLite extension not loaded");
|
||||||
}
|
}
|
||||||
$this->clearData();
|
$this->clearData();
|
||||||
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
||||||
|
if(!$conf) {
|
||||||
$conf = new Conf();
|
$conf = new Conf();
|
||||||
|
}
|
||||||
$conf->dbDriver = Db\SQLite3\Driver::class;
|
$conf->dbDriver = Db\SQLite3\Driver::class;
|
||||||
$conf->dbSchemaBase = $this->vfs->url();
|
$conf->dbSchemaBase = $this->vfs->url();
|
||||||
$this->base = $this->vfs->url()."/SQLite3/";
|
|
||||||
$conf->dbSQLite3File = ":memory:";
|
$conf->dbSQLite3File = ":memory:";
|
||||||
Arsse::$conf = $conf;
|
Arsse::$conf = $conf;
|
||||||
|
$this->base = $this->vfs->url()."/SQLite3/";
|
||||||
$this->drv = new Db\SQLite3\Driver(true);
|
$this->drv = new Db\SQLite3\Driver(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,4 +94,18 @@ class TestDbUpdateSQLite3 extends Test\AbstractTest {
|
||||||
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
|
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
|
||||||
$this->assertEquals(Database::SCHEMA_VERSION, $this->drv->schemaVersion());
|
$this->assertEquals(Database::SCHEMA_VERSION, $this->drv->schemaVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDeclineManualUpdate() {
|
||||||
|
// turn auto-updating off
|
||||||
|
$conf = new Conf();
|
||||||
|
$conf->dbAutoUpdate = false;
|
||||||
|
$this->setUp($conf);
|
||||||
|
$this->assertException("updateManual", "Db");
|
||||||
|
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDeclineDowngrade() {
|
||||||
|
$this->assertException("updateTooNew", "Db");
|
||||||
|
$this->drv->schemaUpdate(-1);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,8 @@ namespace JKingWeb\Arsse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \JKingWeb\Arsse\User
|
* @covers \JKingWeb\Arsse\User
|
||||||
* @covers \JKingWeb\Arsse\User\Internal\Driver */
|
* @covers \JKingWeb\Arsse\User\Internal\Driver
|
||||||
|
* @covers \JKingWeb\Arsse\User\Internal\InternalFunctions */
|
||||||
class TestUserInternalDriver extends Test\AbstractTest {
|
class TestUserInternalDriver extends Test\AbstractTest {
|
||||||
use Test\User\CommonTests;
|
use Test\User\CommonTests;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue