Browse Source

Clean up configuration setting in tests

tags/0.5.0
J. King 7 months ago
parent
commit
d40243a84c

+ 5
- 5
tests/cases/Conf/TestConf.php View File

@@ -39,20 +39,20 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
39 39
     }
40 40
 
41 41
     public function testLoadDefaultValues() {
42
-        $this->assertInstanceOf(Conf::class, new Conf());
42
+        $this->assertInstanceOf(Conf::class, new Conf);
43 43
     }
44 44
 
45 45
     /** @depends testLoadDefaultValues */
46 46
     public function testImportFromArray() {
47 47
         $arr = ['lang' => "xx"];
48
-        $conf = new Conf();
48
+        $conf = new Conf;
49 49
         $conf->import($arr);
50 50
         $this->assertEquals("xx", $conf->lang);
51 51
     }
52 52
 
53 53
     /** @depends testImportFromArray */
54 54
     public function testImportFromFile() {
55
-        $conf = new Conf();
55
+        $conf = new Conf;
56 56
         $conf->importFile(self::$path."confGood");
57 57
         $this->assertEquals("xx", $conf->lang);
58 58
         $conf = new Conf(self::$path."confGood");
@@ -97,7 +97,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
97 97
     }
98 98
 
99 99
     public function testExportToArray() {
100
-        $conf = new Conf();
100
+        $conf = new Conf;
101 101
         $conf->lang = ["en", "fr"]; // should not be exported: not scalar
102 102
         $conf->dbSQLite3File = "test.db"; // should be exported: value changed
103 103
         $conf->userDriver = null; // should be exported: changed value, even when null
@@ -116,7 +116,7 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
116 116
     /** @depends testExportToArray
117 117
      * @depends testImportFromFile */
118 118
     public function testExportToFile() {
119
-        $conf = new Conf();
119
+        $conf = new Conf;
120 120
         $conf->lang = ["en", "fr"]; // should not be exported: not scalar
121 121
         $conf->dbSQLite3File = "test.db"; // should be exported: value changed
122 122
         $conf->userDriver = null; // should be exported: changed value, even when null

+ 1
- 2
tests/cases/Db/SQLite3/TestCreation.php View File

@@ -107,8 +107,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
107 107
         chmod($path."Awal/arsse.db-wal", 0111);
108 108
         chmod($path."Ashm/arsse.db-shm", 0111);
109 109
         // set up configuration
110
-        Arsse::$conf = new Conf();
111
-        Arsse::$conf->dbSQLite3File = ":memory:";
110
+        $this->setConf(['dbSQLite3File' => ":memory:"]);
112 111
     }
113 112
 
114 113
     public function tearDown() {

+ 5
- 5
tests/cases/Db/SQLite3/TestDriver.php View File

@@ -26,11 +26,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
26 26
             $this->markTestSkipped("SQLite extension not loaded");
27 27
         }
28 28
         $this->clearData();
29
-        $conf = new Conf();
30
-        Arsse::$conf = $conf;
31
-        $conf->dbDriver = Driver::class;
32
-        $conf->dbSQLite3Timeout = 0;
33
-        $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
29
+        $this->setConf([
30
+            'dbDriver' => Driver::class,
31
+            'dbSQLite3Timeout' => 0,
32
+            'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'),
33
+        ]);
34 34
         $this->drv = new Driver();
35 35
         $this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File);
36 36
         $this->ch->enableExceptions(true);

+ 2
- 4
tests/cases/Db/SQLite3/TestUpdate.php View File

@@ -31,9 +31,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
31 31
         }
32 32
         $this->clearData();
33 33
         $this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
34
-        if (!$conf) {
35
-            $conf = new Conf();
36
-        }
34
+        $conf = $conf ?? new Conf;
37 35
         $conf->dbDriver = Driver::class;
38 36
         $conf->dbSQLite3File = ":memory:";
39 37
         Arsse::$conf = $conf;
@@ -111,7 +109,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
111 109
 
112 110
     public function testDeclineManualUpdate() {
113 111
         // turn auto-updating off
114
-        $conf = new Conf();
112
+        $conf = new Conf;
115 113
         $conf->dbAutoUpdate = false;
116 114
         $this->setUp($conf);
117 115
         $this->assertException("updateManual", "Db");

+ 1
- 2
tests/cases/Db/SQLite3PDO/TestCreation.php View File

@@ -108,8 +108,7 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
108 108
         chmod($path."Awal/arsse.db-wal", 0111);
109 109
         chmod($path."Ashm/arsse.db-shm", 0111);
110 110
         // set up configuration
111
-        Arsse::$conf = new Conf();
112
-        Arsse::$conf->dbSQLite3File = ":memory:";
111
+        $this->setConf(['dbSQLite3File' => ":memory:"]);
113 112
     }
114 113
 
115 114
     public function tearDown() {

+ 5
- 5
tests/cases/Db/SQLite3PDO/TestDriver.php View File

@@ -27,11 +27,11 @@ class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
27 27
             $this->markTestSkipped("PDO-SQLite extension not loaded");
28 28
         }
29 29
         $this->clearData();
30
-        $conf = new Conf();
31
-        Arsse::$conf = $conf;
32
-        $conf->dbDriver = PDODriver::class;
33
-        $conf->dbSQLite3Timeout = 0;
34
-        $conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
30
+        $this->setConf([
31
+            'dbDriver' => PDODriver::class,
32
+            'dbSQLite3Timeout' => 0,
33
+            'dbSQLite3File' => tempnam(sys_get_temp_dir(), 'ook'),
34
+        ]);
35 35
         $this->drv = new PDODriver();
36 36
         $this->ch = new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
37 37
     }

+ 1
- 1
tests/cases/Feed/TestFeed.php View File

@@ -96,7 +96,7 @@ class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
96 96
         }
97 97
         $this->base = self::$host."Feed/";
98 98
         $this->clearData();
99
-        Arsse::$conf = new Conf();
99
+        $this->setConf();
100 100
         Arsse::$db = Phake::mock(Database::class);
101 101
     }
102 102
 

+ 1
- 1
tests/cases/Feed/TestFetching.php View File

@@ -26,7 +26,7 @@ class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest {
26 26
         }
27 27
         $this->base = self::$host."Feed/";
28 28
         $this->clearData();
29
-        Arsse::$conf = new Conf();
29
+        $this->setConf();
30 30
     }
31 31
 
32 32
     public function testHandle400() {

+ 1
- 1
tests/cases/REST/NextCloudNews/TestV1_2.php View File

@@ -340,7 +340,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
340 340
 
341 341
     public function setUp() {
342 342
         $this->clearData();
343
-        Arsse::$conf = new Conf();
343
+        $this->setConf();
344 344
         // create a mock user manager
345 345
         Arsse::$user = Phake::mock(User::class);
346 346
         Phake::when(Arsse::$user)->auth->thenReturn(true);

+ 3
- 3
tests/cases/REST/TinyTinyRSS/TestAPI.php View File

@@ -177,7 +177,7 @@ LONG_STRING;
177 177
 
178 178
     public function setUp() {
179 179
         $this->clearData();
180
-        Arsse::$conf = new Conf();
180
+        $this->setConf();
181 181
         // create a mock user manager
182 182
         Arsse::$user = Phake::mock(User::class);
183 183
         Phake::when(Arsse::$user)->auth->thenReturn(true);
@@ -226,7 +226,7 @@ LONG_STRING;
226 226
     /** @dataProvider provideLoginRequests */
227 227
     public function testLogIn(array $conf, $httpUser, array $data, $sessions) {
228 228
         Arsse::$user->id = null;
229
-        Arsse::$conf = (new Conf)->import($conf);
229
+        $this->setConf($conf);
230 230
         Phake::when(Arsse::$user)->auth->thenReturn(false);
231 231
         Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true);
232 232
         Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true);
@@ -260,7 +260,7 @@ LONG_STRING;
260 260
     /** @dataProvider provideResumeRequests */
261 261
     public function testValidateASession(array $conf, $httpUser, string $data, $result) {
262 262
         Arsse::$user->id = null;
263
-        Arsse::$conf = (new Conf)->import($conf);
263
+        $this->setConf($conf);
264 264
         Phake::when(Arsse::$db)->sessionResume("PriestsOfSyrinx")->thenReturn([
265 265
             'id' => "PriestsOfSyrinx",
266 266
             'created' => "2000-01-01 00:00:00",

+ 2
- 2
tests/cases/REST/TinyTinyRSS/TestIcon.php View File

@@ -24,7 +24,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
24 24
 
25 25
     public function setUp() {
26 26
         $this->clearData();
27
-        Arsse::$conf = new Conf();
27
+        $this->setConf();
28 28
         // create a mock user manager
29 29
         Arsse::$user = Phake::mock(User::class);
30 30
         // create a mock database interface
@@ -108,7 +108,7 @@ class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
108 108
         $this->assertMessage($exp, $this->reqAuthFailed("42.ico"));
109 109
         $this->assertMessage($exp, $this->reqAuthFailed("1337.ico"));
110 110
         // with HTTP auth required, only authenticated requests should succeed
111
-        Arsse::$conf = (new Conf())->import(['userHTTPAuthRequired' => true]);
111
+        $this->setConf(['userHTTPAuthRequired' => true]);
112 112
         $exp = new Response(301, ['Location' => "http://example.org/icon.gif"]);
113 113
         $this->assertMessage($exp, $this->reqAuth("42.ico"));
114 114
         $this->assertMessage($exp, $this->reqAuth("1337.ico"));

+ 1
- 1
tests/cases/Service/TestService.php View File

@@ -19,7 +19,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
19 19
 
20 20
     public function setUp() {
21 21
         $this->clearData();
22
-        Arsse::$conf = new Conf();
22
+        $this->setConf();
23 23
         Arsse::$db = Phake::mock(Database::class);
24 24
         $this->srv = new Service();
25 25
     }

+ 1
- 2
tests/lib/Database/Setup.php View File

@@ -22,8 +22,7 @@ trait Setup {
22 22
     public function setUp() {
23 23
         // establish a clean baseline
24 24
         $this->clearData();
25
-        // create a default configuration
26
-        Arsse::$conf = new Conf();
25
+        $this->setConf();
27 26
         // configure and create the relevant database driver
28 27
         $this->setUpDriver();
29 28
         // create the database interface with the suitable driver

Loading…
Cancel
Save