diff --git a/tests/cases/Conf/TestConf.php b/tests/cases/Conf/TestConf.php index edfcfbb..73bec5f 100644 --- a/tests/cases/Conf/TestConf.php +++ b/tests/cases/Conf/TestConf.php @@ -39,20 +39,20 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { } public function testLoadDefaultValues() { - $this->assertInstanceOf(Conf::class, new Conf()); + $this->assertInstanceOf(Conf::class, new Conf); } /** @depends testLoadDefaultValues */ public function testImportFromArray() { $arr = ['lang' => "xx"]; - $conf = new Conf(); + $conf = new Conf; $conf->import($arr); $this->assertEquals("xx", $conf->lang); } /** @depends testImportFromArray */ public function testImportFromFile() { - $conf = new Conf(); + $conf = new Conf; $conf->importFile(self::$path."confGood"); $this->assertEquals("xx", $conf->lang); $conf = new Conf(self::$path."confGood"); @@ -97,7 +97,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { } public function testExportToArray() { - $conf = new Conf(); + $conf = new Conf; $conf->lang = ["en", "fr"]; // should not be exported: not scalar $conf->dbSQLite3File = "test.db"; // should be exported: value changed $conf->userDriver = null; // should be exported: changed value, even when null @@ -116,7 +116,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest { /** @depends testExportToArray * @depends testImportFromFile */ public function testExportToFile() { - $conf = new Conf(); + $conf = new Conf; $conf->lang = ["en", "fr"]; // should not be exported: not scalar $conf->dbSQLite3File = "test.db"; // should be exported: value changed $conf->userDriver = null; // should be exported: changed value, even when null diff --git a/tests/cases/Db/SQLite3/TestCreation.php b/tests/cases/Db/SQLite3/TestCreation.php index 4f04918..f9ac55b 100644 --- a/tests/cases/Db/SQLite3/TestCreation.php +++ b/tests/cases/Db/SQLite3/TestCreation.php @@ -107,8 +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 - Arsse::$conf = new Conf(); - Arsse::$conf->dbSQLite3File = ":memory:"; + $this->setConf(['dbSQLite3File' => ":memory:"]); } public function tearDown() { diff --git a/tests/cases/Db/SQLite3/TestDriver.php b/tests/cases/Db/SQLite3/TestDriver.php index 6453326..835ad09 100644 --- a/tests/cases/Db/SQLite3/TestDriver.php +++ b/tests/cases/Db/SQLite3/TestDriver.php @@ -26,11 +26,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest { $this->markTestSkipped("SQLite extension not loaded"); } $this->clearData(); - $conf = new Conf(); - Arsse::$conf = $conf; - $conf->dbDriver = Driver::class; - $conf->dbSQLite3Timeout = 0; - $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook'); + $this->setConf([ + 'dbDriver' => Driver::class, + 'dbSQLite3Timeout' => 0, + 'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'), + ]); $this->drv = new Driver(); $this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File); $this->ch->enableExceptions(true); diff --git a/tests/cases/Db/SQLite3/TestUpdate.php b/tests/cases/Db/SQLite3/TestUpdate.php index d6c8fc3..2ff02e8 100644 --- a/tests/cases/Db/SQLite3/TestUpdate.php +++ b/tests/cases/Db/SQLite3/TestUpdate.php @@ -31,9 +31,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest { } $this->clearData(); $this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]); - if (!$conf) { - $conf = new Conf(); - } + $conf = $conf ?? new Conf; $conf->dbDriver = Driver::class; $conf->dbSQLite3File = ":memory:"; Arsse::$conf = $conf; @@ -111,7 +109,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest { public function testDeclineManualUpdate() { // turn auto-updating off - $conf = new Conf(); + $conf = new Conf; $conf->dbAutoUpdate = false; $this->setUp($conf); $this->assertException("updateManual", "Db"); diff --git a/tests/cases/Db/SQLite3PDO/TestCreation.php b/tests/cases/Db/SQLite3PDO/TestCreation.php index 34cb824..4f2e1a2 100644 --- a/tests/cases/Db/SQLite3PDO/TestCreation.php +++ b/tests/cases/Db/SQLite3PDO/TestCreation.php @@ -108,8 +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 - Arsse::$conf = new Conf(); - Arsse::$conf->dbSQLite3File = ":memory:"; + $this->setConf(['dbSQLite3File' => ":memory:"]); } public function tearDown() { diff --git a/tests/cases/Db/SQLite3PDO/TestDriver.php b/tests/cases/Db/SQLite3PDO/TestDriver.php index 1fec09c..6d58f51 100644 --- a/tests/cases/Db/SQLite3PDO/TestDriver.php +++ b/tests/cases/Db/SQLite3PDO/TestDriver.php @@ -27,11 +27,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest { $this->markTestSkipped("PDO-SQLite extension not loaded"); } $this->clearData(); - $conf = new Conf(); - Arsse::$conf = $conf; - $conf->dbDriver = PDODriver::class; - $conf->dbSQLite3Timeout = 0; - $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook'); + $this->setConf([ + 'dbDriver' => PDODriver::class, + 'dbSQLite3Timeout' => 0, + 'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'), + ]); $this->drv = new PDODriver(); $this->ch = new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); } diff --git a/tests/cases/Feed/TestFeed.php b/tests/cases/Feed/TestFeed.php index fde0195..a1ca84b 100644 --- a/tests/cases/Feed/TestFeed.php +++ b/tests/cases/Feed/TestFeed.php @@ -96,7 +96,7 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest { } $this->base = self::$host."Feed/"; $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); Arsse::$db = Phake::mock(Database::class); } diff --git a/tests/cases/Feed/TestFetching.php b/tests/cases/Feed/TestFetching.php index afe1391..25d4d7c 100644 --- a/tests/cases/Feed/TestFetching.php +++ b/tests/cases/Feed/TestFetching.php @@ -26,7 +26,7 @@ class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest { } $this->base = self::$host."Feed/"; $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); } public function testHandle400() { diff --git a/tests/cases/REST/NextCloudNews/TestV1_2.php b/tests/cases/REST/NextCloudNews/TestV1_2.php index 2ee0b1b..d3a9a9b 100644 --- a/tests/cases/REST/NextCloudNews/TestV1_2.php +++ b/tests/cases/REST/NextCloudNews/TestV1_2.php @@ -340,7 +340,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest { public function setUp() { $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); // create a mock user manager Arsse::$user = Phake::mock(User::class); Phake::when(Arsse::$user)->auth->thenReturn(true); diff --git a/tests/cases/REST/TinyTinyRSS/TestAPI.php b/tests/cases/REST/TinyTinyRSS/TestAPI.php index 9aea12e..62ba256 100644 --- a/tests/cases/REST/TinyTinyRSS/TestAPI.php +++ b/tests/cases/REST/TinyTinyRSS/TestAPI.php @@ -177,7 +177,7 @@ LONG_STRING; public function setUp() { $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); // create a mock user manager Arsse::$user = Phake::mock(User::class); Phake::when(Arsse::$user)->auth->thenReturn(true); @@ -226,7 +226,7 @@ LONG_STRING; /** @dataProvider provideLoginRequests */ public function testLogIn(array $conf, $httpUser, array $data, $sessions) { Arsse::$user->id = null; - Arsse::$conf = (new Conf)->import($conf); + $this->setConf($conf); Phake::when(Arsse::$user)->auth->thenReturn(false); Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true); Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true); @@ -260,7 +260,7 @@ LONG_STRING; /** @dataProvider provideResumeRequests */ public function testValidateASession(array $conf, $httpUser, string $data, $result) { Arsse::$user->id = null; - Arsse::$conf = (new Conf)->import($conf); + $this->setConf($conf); Phake::when(Arsse::$db)->sessionResume("PriestsOfSyrinx")->thenReturn([ 'id' => "PriestsOfSyrinx", 'created' => "2000-01-01 00:00:00", diff --git a/tests/cases/REST/TinyTinyRSS/TestIcon.php b/tests/cases/REST/TinyTinyRSS/TestIcon.php index cb74f67..53db57c 100644 --- a/tests/cases/REST/TinyTinyRSS/TestIcon.php +++ b/tests/cases/REST/TinyTinyRSS/TestIcon.php @@ -24,7 +24,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest { public function setUp() { $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); // create a mock user manager Arsse::$user = Phake::mock(User::class); // create a mock database interface @@ -108,7 +108,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertMessage($exp, $this->reqAuthFailed("42.ico")); $this->assertMessage($exp, $this->reqAuthFailed("1337.ico")); // with HTTP auth required, only authenticated requests should succeed - Arsse::$conf = (new Conf())->import(['userHTTPAuthRequired' => true]); + $this->setConf(['userHTTPAuthRequired' => true]); $exp = new Response(301, ['Location' => "http://example.org/icon.gif"]); $this->assertMessage($exp, $this->reqAuth("42.ico")); $this->assertMessage($exp, $this->reqAuth("1337.ico")); diff --git a/tests/cases/Service/TestService.php b/tests/cases/Service/TestService.php index 1ec4a3d..3ba18e0 100644 --- a/tests/cases/Service/TestService.php +++ b/tests/cases/Service/TestService.php @@ -19,7 +19,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest { public function setUp() { $this->clearData(); - Arsse::$conf = new Conf(); + $this->setConf(); Arsse::$db = Phake::mock(Database::class); $this->srv = new Service(); } diff --git a/tests/lib/Database/Setup.php b/tests/lib/Database/Setup.php index c9b982f..0a98edf 100644 --- a/tests/lib/Database/Setup.php +++ b/tests/lib/Database/Setup.php @@ -22,8 +22,7 @@ trait Setup { public function setUp() { // establish a clean baseline $this->clearData(); - // create a default configuration - Arsse::$conf = new Conf(); + $this->setConf(); // configure and create the relevant database driver $this->setUpDriver(); // create the database interface with the suitable driver