1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Clean up configuration setting in tests

This commit is contained in:
J. King 2018-11-04 09:16:34 -05:00
parent 0be9dcb5a8
commit d40243a84c
13 changed files with 29 additions and 34 deletions

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

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

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

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

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

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

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

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

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

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

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

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

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