2018-11-23 14:29:06 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\TestCase\Database;
|
|
|
|
|
2018-11-25 04:18:17 +00:00
|
|
|
use JKingWeb\Arsse\Test\Database;
|
2018-11-23 14:29:06 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\User;
|
|
|
|
|
2019-09-11 19:25:26 +00:00
|
|
|
abstract class AbstractTest extends \JKingWeb\Arsse\Test\AbstractTest {
|
2018-11-25 05:03:56 +00:00
|
|
|
use SeriesMiscellany;
|
|
|
|
use SeriesMeta;
|
|
|
|
use SeriesUser;
|
|
|
|
use SeriesSession;
|
2019-03-09 21:23:56 +00:00
|
|
|
use SeriesToken;
|
2018-11-25 05:03:56 +00:00
|
|
|
use SeriesFolder;
|
2023-02-04 02:52:27 +00:00
|
|
|
use SeriesFeed;
|
2020-11-05 21:51:46 +00:00
|
|
|
use SeriesIcon;
|
2022-10-07 22:38:17 +00:00
|
|
|
use SeriesSubscription;
|
2023-02-25 01:35:24 +00:00
|
|
|
use SeriesLabel;
|
2019-03-07 03:15:41 +00:00
|
|
|
use SeriesTag;
|
2023-02-05 14:26:59 +00:00
|
|
|
use SeriesArticle;
|
2023-03-14 23:58:33 +00:00
|
|
|
use SeriesCleanup;
|
2018-11-25 04:18:17 +00:00
|
|
|
|
|
|
|
/** @var \JKingWeb\Arsse\Db\Driver */
|
|
|
|
protected static $drv;
|
|
|
|
protected static $failureReason = "";
|
2018-11-23 14:29:06 +00:00
|
|
|
protected $primed = false;
|
2023-01-27 20:33:34 +00:00
|
|
|
protected $data;
|
|
|
|
protected $user;
|
|
|
|
protected $checkTables;
|
|
|
|
protected $series;
|
2018-11-23 14:29:06 +00:00
|
|
|
|
2018-12-05 22:28:11 +00:00
|
|
|
abstract protected function nextID(string $table): int;
|
2018-11-23 14:29:06 +00:00
|
|
|
|
2018-11-25 04:18:17 +00:00
|
|
|
protected function findTraitOfTest(string $test): string {
|
|
|
|
$class = new \ReflectionClass(self::class);
|
|
|
|
foreach ($class->getTraits() as $trait) {
|
|
|
|
if ($trait->hasMethod($test)) {
|
|
|
|
return $trait->getShortName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $class->getShortName();
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public static function setUpBeforeClass(): void {
|
2018-11-23 14:29:06 +00:00
|
|
|
// establish a clean baseline
|
2018-11-25 04:18:17 +00:00
|
|
|
static::clearData();
|
|
|
|
// perform an initial connection to the database to reset its version to zero
|
2018-12-05 22:28:11 +00:00
|
|
|
// in the case of SQLite this will always be the case (we use a memory database),
|
2018-11-25 04:18:17 +00:00
|
|
|
// but other engines should clean up from potentially interrupted prior tests
|
|
|
|
static::setConf();
|
|
|
|
try {
|
2019-01-12 17:43:06 +00:00
|
|
|
static::$drv = new static::$dbDriverClass;
|
2018-11-25 04:18:17 +00:00
|
|
|
} catch (\JKingWeb\Arsse\Db\Exception $e) {
|
|
|
|
static::$failureReason = $e->getMessage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// wipe the database absolutely clean
|
2019-01-12 17:43:06 +00:00
|
|
|
static::dbRaze(static::$drv);
|
2018-11-25 04:18:17 +00:00
|
|
|
// create the database interface with the suitable driver and apply the latest schema
|
|
|
|
Arsse::$db = new Database(static::$drv);
|
2018-11-23 14:29:06 +00:00
|
|
|
Arsse::$db->driverSchemaUpdate();
|
2018-11-25 04:18:17 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public function setUp(): void {
|
2018-11-25 04:18:17 +00:00
|
|
|
// get the name of the test's test series
|
2019-02-25 21:26:38 +00:00
|
|
|
$this->series = $this->findTraitofTest($this->getName(false));
|
2018-11-25 04:18:17 +00:00
|
|
|
static::clearData();
|
2018-11-25 05:03:56 +00:00
|
|
|
static::setConf();
|
2018-11-25 04:18:17 +00:00
|
|
|
if (strlen(static::$failureReason)) {
|
|
|
|
$this->markTestSkipped(static::$failureReason);
|
|
|
|
}
|
|
|
|
Arsse::$db = new Database(static::$drv);
|
2018-11-28 17:12:49 +00:00
|
|
|
Arsse::$db->driverSchemaUpdate();
|
2018-11-23 14:29:06 +00:00
|
|
|
// create a mock user manager
|
2021-02-27 20:24:02 +00:00
|
|
|
$this->userMock = $this->mock(User::class);
|
|
|
|
Arsse::$user = $this->userMock->get();
|
2018-11-25 04:18:17 +00:00
|
|
|
// call the series-specific setup method
|
|
|
|
$setUp = "setUp".$this->series;
|
|
|
|
$this->$setUp();
|
2018-11-23 14:29:06 +00:00
|
|
|
// prime the database with series data if it hasn't already been done
|
|
|
|
if (!$this->primed && isset($this->data)) {
|
2019-06-21 22:52:27 +00:00
|
|
|
$this->primeDatabase(static::$drv, $this->data);
|
2018-11-23 14:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public function tearDown(): void {
|
2018-11-25 04:18:17 +00:00
|
|
|
// call the series-specific teardown method
|
2019-02-25 21:26:38 +00:00
|
|
|
$this->series = $this->findTraitofTest($this->getName(false));
|
2018-11-25 04:18:17 +00:00
|
|
|
$tearDown = "tearDown".$this->series;
|
|
|
|
$this->$tearDown();
|
2018-11-23 14:29:06 +00:00
|
|
|
// clean up
|
|
|
|
$this->primed = false;
|
2018-11-25 04:18:17 +00:00
|
|
|
// call the database-specific table cleanup function
|
2019-01-12 17:43:06 +00:00
|
|
|
static::dbTruncate(static::$drv);
|
2018-11-25 04:18:17 +00:00
|
|
|
// clear state
|
|
|
|
static::clearData();
|
|
|
|
}
|
|
|
|
|
2019-10-16 18:42:43 +00:00
|
|
|
public static function tearDownAfterClass(): void {
|
2019-03-16 21:48:48 +00:00
|
|
|
if (static::$drv) {
|
|
|
|
// wipe the database absolutely clean
|
|
|
|
static::dbRaze(static::$drv);
|
|
|
|
// clean up
|
|
|
|
static::$drv = null;
|
|
|
|
}
|
2018-11-25 04:18:17 +00:00
|
|
|
static::$failureReason = "";
|
|
|
|
static::clearData();
|
2018-11-23 14:29:06 +00:00
|
|
|
}
|
|
|
|
}
|