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

Test cleanup

This commit is contained in:
J. King 2018-11-16 21:32:27 -05:00
parent edfae438fa
commit 976672de5b
7 changed files with 24 additions and 25 deletions

View file

@ -107,7 +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
$this->setConf(['dbSQLite3File' => ":memory:"]);
$this->setConf();
}
public function tearDown() {

View file

@ -25,16 +25,13 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
const MINIMAL1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
const MINIMAL2 = "pragma user_version=2";
public function setUp(Conf $conf = null) {
public function setUp(array $conf = []) {
if (!Driver::requirementsMet()) {
$this->markTestSkipped("SQLite extension not loaded");
}
$this->clearData();
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
$conf = $conf ?? new Conf;
$conf->dbDriver = Driver::class;
$conf->dbSQLite3File = ":memory:";
Arsse::$conf = $conf;
$this->setConf($conf);
$this->base = $this->vfs->url();
$this->path = $this->base."/SQLite3/";
$this->drv = new Driver();
@ -109,9 +106,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
public function testDeclineManualUpdate() {
// turn auto-updating off
$conf = new Conf;
$conf->dbAutoUpdate = false;
$this->setUp($conf);
$this->setUp(['dbAutoUpdate' => false]);
$this->assertException("updateManual", "Db");
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
}

View file

@ -108,7 +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
$this->setConf(['dbSQLite3File' => ":memory:"]);
$this->setConf();
}
public function tearDown() {

View file

@ -25,18 +25,14 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
const MINIMAL1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
const MINIMAL2 = "pragma user_version=2";
public function setUp(Conf $conf = null) {
public function setUp(array $conf = []) {
if (!PDODriver::requirementsMet()) {
$this->markTestSkipped("PDO-SQLite extension not loaded");
}
$this->clearData();
$this->vfs = vfsStream::setup("schemata", null, ['SQLite3' => []]);
if (!$conf) {
$conf = new Conf();
}
$conf->dbDriver = PDODriver::class;
$conf->dbSQLite3File = ":memory:";
Arsse::$conf = $conf;
$conf['dbDriver'] = PDODriver::class;
$this->setConf($conf);
$this->base = $this->vfs->url();
$this->path = $this->base."/SQLite3/";
$this->drv = new PDODriver();
@ -111,9 +107,7 @@ class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
public function testDeclineManualUpdate() {
// turn auto-updating off
$conf = new Conf();
$conf->dbAutoUpdate = false;
$this->setUp($conf);
$this->setUp(['dbAutoUpdate' => false]);
$this->assertException("updateManual", "Db");
$this->drv->schemaUpdate(Database::SCHEMA_VERSION);
}

View file

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Result;
use JKingWeb\Arsse\Db\PDOResult;
use JKingWeb\Arsse\Db\SQLite3\PDODriver;
@ -16,16 +17,17 @@ use JKingWeb\Arsse\Db\SQLite3\PDODriver;
*/
class TestResult extends \JKingWeb\Arsse\Test\AbstractTest {
public function provideDrivers() {
$this->setConf();
$drvSqlite3 = (function() {
if (\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet()) {
$d = new \SQLite3(":memory:");
$d = new \SQLite3(Arsse::$conf->dbSQLite3File);
$d->enableExceptions(true);
return $d;
}
})();
$drvPdo = (function() {
if (\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) {
return new \PDO("sqlite::memory:", "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
return new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
}
})();
return [

View file

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Statement;
use JKingWeb\Arsse\Db\PDOStatement;
@ -16,16 +17,17 @@ use JKingWeb\Arsse\Db\PDOStatement;
* @covers \JKingWeb\Arsse\Db\PDOError */
class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
public function provideDrivers() {
$this->setConf();
$drvSqlite3 = (function() {
if (\JKingWeb\Arsse\Db\SQLite3\Driver::requirementsMet()) {
$d = new \SQLite3(":memory:");
$d = new \SQLite3(Arsse::$conf->dbSQLite3File);
$d->enableExceptions(true);
return $d;
}
})();
$drvPdo = (function() {
if (\JKingWeb\Arsse\Db\SQLite3\PDODriver::requirementsMet()) {
return new \PDO("sqlite::memory:", "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
return new \PDO("sqlite:".Arsse::$conf->dbSQLite3File, "", "", [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]);
}
})();
return [

View file

@ -41,7 +41,13 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
}
public function setConf(array $conf = []) {
Arsse::$conf = (new Conf)->import($conf);
$defaults = [
'dbSQLite3File' => ":memory:",
'dbPostgreSQLUser' => "arsse_test",
'dbPostgreSQLPass' => "arsse_test",
'dbPostgreSQLDb' => "arsse_test",
];
Arsse::$conf = (new Conf)->import($defaults)->import($conf);
}
public function assertException(string $msg = "", string $prefix = "", string $type = "Exception") {