mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +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 unlock(bool $rollback = false) : bool;
|
||||
|
||||
/** @codeCoverageIgnore */
|
||||
public function schemaVersion(): int {
|
||||
// FIXME: generic schemaVersion() will need to be covered for database engines other than SQLite
|
||||
try {
|
||||
return (int) $this->query("SELECT value from arsse_meta where key is schema_version")->getValue();
|
||||
} catch(Exception $e) {
|
||||
|
|
|
@ -59,9 +59,7 @@ class Statement extends \JKingWeb\Arsse\Db\AbstractStatement {
|
|||
$a += $this->bindValues($value, $a);
|
||||
} else if(array_key_exists($a,$this->types)) {
|
||||
// if the parameter type is something other than the known values, this is an error
|
||||
if(!array_key_exists($this->types[$a], self::BINDINGS)) {
|
||||
throw new Exception("paramTypeUnknown", $this->types[$a]);
|
||||
}
|
||||
assert(array_key_exists($this->types[$a], self::BINDINGS), 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($this->types[$a]=="null" || ($this->isNullable[$a] && is_null($value))) {
|
||||
$this->st->bindValue($a+1, null, \SQLITE3_NULL);
|
||||
|
|
|
@ -39,10 +39,10 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
|
|||
function testIterateOverResults() {
|
||||
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
|
||||
$rows = [];
|
||||
foreach(new Db\SQLite3\Result($set) as $row) {
|
||||
$rows[] = $row['col'];
|
||||
foreach(new Db\SQLite3\Result($set) as $index => $row) {
|
||||
$rows[$index] = $row['col'];
|
||||
}
|
||||
$this->assertEquals([1,2,3], $rows);
|
||||
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
|
||||
}
|
||||
|
||||
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 MINIMAL2 = "pragma user_version=2";
|
||||
|
||||
function setUp() {
|
||||
function setUp(Conf $conf = null) {
|
||||
if(!extension_loaded("sqlite3")) {
|
||||
$this->markTestSkipped("SQLite extension not loaded");
|
||||
}
|
||||
$this->clearData();
|
||||
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
|
||||
$conf = new Conf();
|
||||
if(!$conf) {
|
||||
$conf = new Conf();
|
||||
}
|
||||
$conf->dbDriver = Db\SQLite3\Driver::class;
|
||||
$conf->dbSchemaBase = $this->vfs->url();
|
||||
$this->base = $this->vfs->url()."/SQLite3/";
|
||||
$conf->dbSQLite3File = ":memory:";
|
||||
Arsse::$conf = $conf;
|
||||
$this->base = $this->vfs->url()."/SQLite3/";
|
||||
$this->drv = new Db\SQLite3\Driver(true);
|
||||
}
|
||||
|
||||
|
@ -92,4 +94,18 @@ class TestDbUpdateSQLite3 extends Test\AbstractTest {
|
|||
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
|
||||
$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\Internal\Driver */
|
||||
* @covers \JKingWeb\Arsse\User\Internal\Driver
|
||||
* @covers \JKingWeb\Arsse\User\Internal\InternalFunctions */
|
||||
class TestUserInternalDriver extends Test\AbstractTest {
|
||||
use Test\User\CommonTests;
|
||||
|
||||
|
|
Loading…
Reference in a new issue