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;
|
|
|
|
use SeriesFeed;
|
|
|
|
use SeriesSubscription;
|
|
|
|
use SeriesLabel;
|
2019-03-07 03:15:41 +00:00
|
|
|
use SeriesTag;
|
|
|
|
use SeriesArticle;
|
2018-11-25 05:03:56 +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;
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
// 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
|
2019-09-05 14:03:32 +00:00
|
|
|
Arsse::$user = \Phake::mock(User::class);
|
|
|
|
\Phake::when(Arsse::$user)->authorize->thenReturn(true);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function tearDownAfterClass() {
|
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
|
|
|
}
|
|
|
|
}
|