Browse Source

Clean up configuration setting in tests

tags/0.5.0
J. King 10 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 {
}

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

@@ -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