From 70f76f77fa607ca5f5918813fd04174548f8512f Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 21 Jul 2017 11:13:04 -0400 Subject: [PATCH] More test coverage tweaks --- lib/Db/AbstractDriver.php | 2 ++ lib/Db/SQLite3/Statement.php | 4 +--- tests/Db/SQLite3/TestDbResultSQLite3.php | 6 +++--- tests/Db/SQLite3/TestDbUpdateSQLite3.php | 22 +++++++++++++++++++--- tests/User/TestUserInternalDriver.php | 3 ++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/Db/AbstractDriver.php b/lib/Db/AbstractDriver.php index 03e907b..b5885c5 100644 --- a/lib/Db/AbstractDriver.php +++ b/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) { diff --git a/lib/Db/SQLite3/Statement.php b/lib/Db/SQLite3/Statement.php index 05db69d..38fafc3 100644 --- a/lib/Db/SQLite3/Statement.php +++ b/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); diff --git a/tests/Db/SQLite3/TestDbResultSQLite3.php b/tests/Db/SQLite3/TestDbResultSQLite3.php index a241119..f52754c 100644 --- a/tests/Db/SQLite3/TestDbResultSQLite3.php +++ b/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() { diff --git a/tests/Db/SQLite3/TestDbUpdateSQLite3.php b/tests/Db/SQLite3/TestDbUpdateSQLite3.php index 18fea7b..f8a99ce 100644 --- a/tests/Db/SQLite3/TestDbUpdateSQLite3.php +++ b/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); + } } \ No newline at end of file diff --git a/tests/User/TestUserInternalDriver.php b/tests/User/TestUserInternalDriver.php index 9264c7f..e29204c 100644 --- a/tests/User/TestUserInternalDriver.php +++ b/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;