Browse Source

More test coverage tweaks

microsub
J. King 7 years ago
parent
commit
70f76f77fa
  1. 2
      lib/Db/AbstractDriver.php
  2. 4
      lib/Db/SQLite3/Statement.php
  3. 6
      tests/Db/SQLite3/TestDbResultSQLite3.php
  4. 22
      tests/Db/SQLite3/TestDbUpdateSQLite3.php
  5. 3
      tests/User/TestUserInternalDriver.php

2
lib/Db/AbstractDriver.php

@ -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) {

4
lib/Db/SQLite3/Statement.php

@ -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);

6
tests/Db/SQLite3/TestDbResultSQLite3.php

@ -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() {

22
tests/Db/SQLite3/TestDbUpdateSQLite3.php

@ -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);
}
}

3
tests/User/TestUserInternalDriver.php

@ -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…
Cancel
Save