markTestSkipped(static::$implementation." database driver not available"); } self::clearData(); self::setConf(); // construct a fresh driver for each test $this->drv = new static::$dbDriverClass; $schemaId = (get_class($this->drv))::schemaID(); // set up a virtual filesystem for schema files $this->vfs = vfsStream::setup("schemata", null, [$schemaId => []]); $this->base = $this->vfs->url(); $this->path = $this->base."/$schemaId/"; // completely clear the database static::dbRaze(static::$interface); } public function tearDown(): void { // deconstruct the driver unset($this->drv); unset($this->path, $this->base, $this->vfs); self::clearData(); } public static function tearDownAfterClass(): void { if (static::$interface) { // completely clear the database static::dbRaze(static::$interface); } static::$interface = null; self::clearData(); } public function testLoadMissingFile(): void { $this->assertException("updateFileMissing", "Db"); $this->drv->schemaUpdate(1, $this->base); } public function testLoadUnreadableFile(): void { touch($this->path."0.sql"); chmod($this->path."0.sql", 0000); $this->assertException("updateFileUnreadable", "Db"); $this->drv->schemaUpdate(1, $this->base); } public function testLoadCorruptFile(): void { file_put_contents($this->path."0.sql", "This is a corrupt file"); $this->assertException("updateFileError", "Db"); $this->drv->schemaUpdate(1, $this->base); } public function testLoadIncompleteFile(): void { file_put_contents($this->path."0.sql", "create table arsse_meta(\"key\" varchar(255) primary key not null, value text);"); $this->assertException("updateFileIncomplete", "Db"); $this->drv->schemaUpdate(1, $this->base); } public function testLoadEmptyFile(): void { file_put_contents($this->path."0.sql", ""); $this->assertException("updateFileIncomplete", "Db"); $this->drv->schemaUpdate(1, $this->base); } public function testLoadCorrectFile(): void { file_put_contents($this->path."0.sql", static::$minimal1); $this->drv->schemaUpdate(1, $this->base); $this->assertEquals(1, $this->drv->schemaVersion()); } public function testPerformPartialUpdate(): void { file_put_contents($this->path."0.sql", static::$minimal1); file_put_contents($this->path."1.sql", "UPDATE arsse_meta set value = '1' where \"key\" = 'schema_version'"); $this->assertException("updateFileIncomplete", "Db"); try { $this->drv->schemaUpdate(2, $this->base); } catch (Exception $e) { $this->assertEquals(1, $this->drv->schemaVersion()); throw $e; } } public function testPerformSequentialUpdate(): void { file_put_contents($this->path."0.sql", static::$minimal1); file_put_contents($this->path."1.sql", static::$minimal2); $this->drv->schemaUpdate(2, $this->base); $this->assertEquals(2, $this->drv->schemaVersion()); } public function testPerformActualUpdate(): void { $this->drv->schemaUpdate(Database::SCHEMA_VERSION); $this->assertEquals(Database::SCHEMA_VERSION, $this->drv->schemaVersion()); } public function testDeclineManualUpdate(): void { // turn auto-updating off Arsse::$conf->dbAutoUpdate = false; $this->assertException("updateManual", "Db"); $this->drv->schemaUpdate(Database::SCHEMA_VERSION); } public function testDeclineDowngrade(): void { $this->assertException("updateTooNew", "Db"); $this->drv->schemaUpdate(-1, $this->base); } public function testPerformMaintenance(): void { $this->drv->schemaUpdate(Database::SCHEMA_VERSION); $this->assertTrue($this->drv->maintenance()); } public function testUpdateTo7(): void { $this->drv->schemaUpdate(6); $this->drv->exec( <<drv->schemaUpdate(7); $users = [ ['id' => "a", 'password' => "xyz", 'num' => 1], ['id' => "b", 'password' => "abc", 'num' => 2], ]; $folders = [ ['owner' => "a", 'name' => "1"], ['owner' => "b", 'name' => "2"], ]; $icons = [ ['id' => 1, 'url' => "http://example.com/icon"], ['id' => 2, 'url' => "http://example.org/icon"], ]; $feeds = [ ['url' => 'http://example.com/', 'icon' => 1], ['url' => 'http://example.org/', 'icon' => 2], ['url' => 'https://example.com/', 'icon' => 1], ['url' => 'http://example.net/', 'icon' => null], ]; $subs = [ ['id' => 1, 'scrape' => 1], ['id' => 2, 'scrape' => 1], ['id' => 3, 'scrape' => 0], ['id' => 4, 'scrape' => 0], ]; $this->assertEquals($users, $this->drv->query("SELECT id, password, num from arsse_users order by id")->getAll()); $this->assertEquals($folders, $this->drv->query("SELECT owner, name from arsse_folders order by owner")->getAll()); $this->assertEquals($icons, $this->drv->query("SELECT id, url from arsse_icons order by id")->getAll()); $this->assertEquals($feeds, $this->drv->query("SELECT url, icon from arsse_feeds order by id")->getAll()); $this->assertEquals($subs, $this->drv->query("SELECT id, scrape from arsse_subscriptions order by id")->getAll()); } }