Browse Source

Clean up configuration setting in tests

microsub
J. King 5 years ago
parent
commit
d40243a84c
  1. 10
      tests/cases/Conf/TestConf.php
  2. 3
      tests/cases/Db/SQLite3/TestCreation.php
  3. 10
      tests/cases/Db/SQLite3/TestDriver.php
  4. 6
      tests/cases/Db/SQLite3/TestUpdate.php
  5. 3
      tests/cases/Db/SQLite3PDO/TestCreation.php
  6. 10
      tests/cases/Db/SQLite3PDO/TestDriver.php
  7. 2
      tests/cases/Feed/TestFeed.php
  8. 2
      tests/cases/Feed/TestFetching.php
  9. 2
      tests/cases/REST/NextCloudNews/TestV1_2.php
  10. 6
      tests/cases/REST/TinyTinyRSS/TestAPI.php
  11. 4
      tests/cases/REST/TinyTinyRSS/TestIcon.php
  12. 2
      tests/cases/Service/TestService.php
  13. 3
      tests/lib/Database/Setup.php

10
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

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

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

6
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");

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

10
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]);
}

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

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

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

6
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",

4
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"));

2
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();
}

3
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

Loading…
Cancel
Save