From 976672de5bac96bf3956d0b3838530a47cf1c9fa Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 16 Nov 2018 21:32:27 -0500 Subject: [PATCH] Test cleanup --- tests/cases/Db/SQLite3/TestCreation.php | 2 +- tests/cases/Db/SQLite3/TestUpdate.php | 11 +++-------- tests/cases/Db/SQLite3PDO/TestCreation.php | 2 +- tests/cases/Db/SQLite3PDO/TestUpdate.php | 14 ++++---------- tests/cases/Db/TestResult.php | 6 ++++-- tests/cases/Db/TestStatement.php | 6 ++++-- tests/lib/AbstractTest.php | 8 +++++++- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/cases/Db/SQLite3/TestCreation.php b/tests/cases/Db/SQLite3/TestCreation.php index f9ac55b..86ba40b 100644 --- a/tests/cases/Db/SQLite3/TestCreation.php +++ b/tests/cases/Db/SQLite3/TestCreation.php @@ -107,7 +107,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest { chmod($path."Awal/arsse.db-wal", 0111); chmod($path."Ashm/arsse.db-shm", 0111); // set up configuration - $this->setConf(['dbSQLite3File' => ":memory:"]); + $this->setConf(); } public function tearDown() { diff --git a/tests/cases/Db/SQLite3/TestUpdate.php b/tests/cases/Db/SQLite3/TestUpdate.php index 2ff02e8..7347eca 100644 --- a/tests/cases/Db/SQLite3/TestUpdate.php +++ b/tests/cases/Db/SQLite3/TestUpdate.php @@ -25,16 +25,13 @@ class TestUpdate extends \JKingWeb\Arsse\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"; - public function setUp(Conf $conf = null) { + public function setUp(array $conf = []) { if (!Driver::requirementsMet()) { $this->markTestSkipped("SQLite extension not loaded"); } $this->clearData(); $this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]); - $conf = $conf ?? new Conf; - $conf->dbDriver = Driver::class; - $conf->dbSQLite3File = ":memory:"; - Arsse::$conf = $conf; + $this->setConf($conf); $this->base = $this->vfs->url(); $this->path = $this->base."/SQLite3/"; $this->drv = new Driver(); @@ -109,9 +106,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest { public function testDeclineManualUpdate() { // turn auto-updating off - $conf = new Conf; - $conf->dbAutoUpdate = false; - $this->setUp($conf); + $this->setUp(['dbAutoUpdate' => false]); $this->assertException("updateManual", "Db"); $this->drv->schemaUpdate(Database::SCHEMA_VERSION); } diff --git a/tests/cases/Db/SQLite3PDO/TestCreation.php b/tests/cases/Db/SQLite3PDO/TestCreation.php index 4f2e1a2..bec5161 100644 --- a/tests/cases/Db/SQLite3PDO/TestCreation.php +++ b/tests/cases/Db/SQLite3PDO/TestCreation.php @@ -108,7 +108,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest { chmod($path."Awal/arsse.db-wal", 0111); chmod($path."Ashm/arsse.db-shm", 0111); // set up configuration - $this->setConf(['dbSQLite3File' => ":memory:"]); + $this->setConf(); } public function tearDown() { diff --git a/tests/cases/Db/SQLite3PDO/TestUpdate.php b/tests/cases/Db/SQLite3PDO/TestUpdate.php index 9c8df84..d58f971 100644 --- a/tests/cases/Db/SQLite3PDO/TestUpdate.php +++ b/tests/cases/Db/SQLite3PDO/TestUpdate.php @@ -25,18 +25,14 @@ class TestUpdate extends \JKingWeb\Arsse\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"; - public function setUp(Conf $conf = null) { + public function setUp(array $conf = []) { if (!PDODriver::requirementsMet()) { $this->markTestSkipped("PDO-SQLite extension not loaded"); } $this->clearData(); $this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]); - if (!$conf) { - $conf = new Conf(); - } - $conf->dbDriver = PDODriver::class; - $conf->dbSQLite3File = ":memory:"; - Arsse::$conf = $conf; + $conf['dbDriver'] = PDODriver::class; + $this->setConf($conf); $this->base = $this->vfs->url(); $this->path = $this->base."/SQLite3/"; $this->drv = new PDODriver(); @@ -111,9 +107,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest { public function testDeclineManualUpdate() { // turn auto-updating off - $conf = new Conf(); - $conf->dbAutoUpdate = false; - $this->setUp($conf); + $this->setUp(['dbAutoUpdate' => false]); $this->assertException("updateManual", "Db"); $this->drv->schemaUpdate(Database::SCHEMA_VERSION); } diff --git a/tests/cases/Db/TestResult.php b/tests/cases/Db/TestResult.php index 9a252b8..eb2e695 100644 --- a/tests/cases/Db/TestResult.php +++ b/tests/cases/Db/TestResult.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Db; +use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Db\Result; use JKingWeb\Arsse\Db\PDOResult; use JKingWeb\Arsse\Db\SQLite3\PDODriver; @@ -16,16 +17,17 @@ use JKingWeb\Arsse\Db\SQLite3\PDODriver; */ class TestResult extends \JKingWeb\Arsse\Test\AbstractTest { public function provideDrivers() { + $this->setConf(); $drvSqlite3 = (function() { if (\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet()) { - $d = new \SQLite3(":memory:"); + $d = new \SQLite3(Arsse::$conf->dbSQLite3File); $d->enableExceptions(true); return $d; } })(); $drvPdo = (function() { if (\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) { - return new \PDO("sqlite::memory:", "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); + return new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); } })(); return [ diff --git a/tests/cases/Db/TestStatement.php b/tests/cases/Db/TestStatement.php index 94a4885..e83106a 100644 --- a/tests/cases/Db/TestStatement.php +++ b/tests/cases/Db/TestStatement.php @@ -6,6 +6,7 @@ declare(strict_types=1); namespace JKingWeb\Arsse\TestCase\Db; +use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Db\Statement; use JKingWeb\Arsse\Db\PDOStatement; @@ -16,16 +17,17 @@ use JKingWeb\Arsse\Db\PDOStatement; * @covers \JKingWeb\Arsse\Db\PDOError */ class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest { public function provideDrivers() { + $this->setConf(); $drvSqlite3 = (function() { if (\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet()) { - $d = new \SQLite3(":memory:"); + $d = new \SQLite3(Arsse::$conf->dbSQLite3File); $d->enableExceptions(true); return $d; } })(); $drvPdo = (function() { if (\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) { - return new \PDO("sqlite::memory:", "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); + return new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); } })(); return [ diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index a75c339..7ad4c7c 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -41,7 +41,13 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } public function setConf(array $conf = []) { - Arsse::$conf = (new Conf)->import($conf); + $defaults = [ + 'dbSQLite3File' => ":memory:", + 'dbPostgreSQLUser' => "arsse_test", + 'dbPostgreSQLPass' => "arsse_test", + 'dbPostgreSQLDb' => "arsse_test", + ]; + Arsse::$conf = (new Conf)->import($defaults)->import($conf); } public function assertException(string $msg = "", string $prefix = "", string $type = "Exception") {