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

Move database driver helps out of test cases

This commit is contained in:
J. King 2019-08-25 13:19:11 -04:00
parent 16530b9a66
commit bab4174a17
36 changed files with 36 additions and 38 deletions

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQL;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected function nextID(string $table): int {
return (int) (static::$drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue() ?? 1);

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQL;
* @covers \JKingWeb\Arsse\Db\MySQL\ExceptionBuilder
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected $create = "CREATE TABLE arsse_test(id bigint auto_increment primary key)";
protected $lock = ["SET lock_wait_timeout = 1", "LOCK TABLES arsse_meta WRITE"];

View file

@ -14,7 +14,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\MySQL\ExceptionBuilder
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected static $createMeta = "CREATE TABLE arsse_meta(`key` varchar(255) primary key not null, value text)";
protected static $createTest = "CREATE TABLE arsse_test(id bigint auto_increment primary key)";

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQL;
* @covers \JKingWeb\Arsse\Db\MySQL\ExceptionBuilder
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected function makeStatement(string $q, array $types = []): array {
return [static::$interface, $q, $types];

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQL;
* @covers \JKingWeb\Arsse\Db\MySQL\ExceptionBuilder
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected static $minimal1 = "CREATE TABLE arsse_meta(`key` varchar(255) primary key, value text); INSERT INTO arsse_meta(`key`,value) values('schema_version','1');";
protected static $minimal2 = "UPDATE arsse_meta set value = '2' where `key` = 'schema_version';";

View file

@ -14,7 +14,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQLPDO;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected function nextID(string $table): int {
return (int) (static::$drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue() ?? 1);

View file

@ -14,7 +14,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected $create = "CREATE TABLE arsse_test(id bigint auto_increment primary key)";
protected $lock = ["SET lock_wait_timeout = 1", "LOCK TABLES arsse_meta WRITE"];

View file

@ -15,7 +15,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected static $createMeta = "CREATE TABLE arsse_meta(`key` varchar(255) primary key not null, value text)";
protected static $createTest = "CREATE TABLE arsse_test(id bigint auto_increment primary key)";

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected function makeStatement(string $q, array $types = []): array {
return [static::$interface, $q, $types];

View file

@ -14,7 +14,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected static $minimal1 = "CREATE TABLE arsse_meta(`key` varchar(255) primary key, value text); INSERT INTO arsse_meta(`key`,value) values('schema_version','1');";
protected static $minimal2 = "UPDATE arsse_meta set value = '2' where `key` = 'schema_version';";

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected function nextID(string $table): int {
return (int) static::$drv->query("SELECT coalesce(last_value, (select max(id) from $table)) + 1 from pg_sequences where sequencename = '{$table}_id_seq'")->getValue();

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Dispatch<extended>
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected $create = "CREATE TABLE arsse_test(id bigserial primary key)";
protected $lock = ["BEGIN", "LOCK TABLE arsse_meta IN EXCLUSIVE MODE NOWAIT"];

View file

@ -13,7 +13,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Result<extended>
*/
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Dispatch<extended>
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected function makeStatement(string $q, array $types = []): array {
return [static::$interface, $q, $types];

View file

@ -11,7 +11,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
* @covers \JKingWeb\Arsse\Db\PostgreSQL\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQL;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected static $minimal1 = "CREATE TABLE arsse_meta(key text primary key, value text); INSERT INTO arsse_meta(key,value) values('schema_version','1');";
protected static $minimal2 = "UPDATE arsse_meta set value = '2' where key = 'schema_version';";

View file

@ -14,7 +14,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected function nextID(string $table): int {
return (int) static::$drv->query("SELECT coalesce(last_value, (select max(id) from $table)) + 1 from pg_sequences where sequencename = '{$table}_id_seq'")->getValue();

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected $create = "CREATE TABLE arsse_test(id bigserial primary key)";
protected $lock = ["BEGIN", "LOCK TABLE arsse_meta IN EXCLUSIVE MODE NOWAIT"];

View file

@ -13,7 +13,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\PDOResult<extended>
*/
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text)";
protected static $createTest = "CREATE TABLE arsse_test(id bigserial primary key)";

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected function makeStatement(string $q, array $types = []): array {
return [static::$interface, $q, $types];

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\PostgreSQLPDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected static $minimal1 = "CREATE TABLE arsse_meta(key text primary key, value text); INSERT INTO arsse_meta(key,value) values('schema_version','1');";
protected static $minimal2 = "UPDATE arsse_meta set value = '2' where key = 'schema_version';";

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
protected function nextID(string $table): int {
return static::$drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue();

View file

@ -10,7 +10,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
protected $create = "CREATE TABLE arsse_test(id integer primary key)";
protected $lock = "BEGIN EXCLUSIVE TRANSACTION";

View file

@ -12,7 +12,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\SQLite3\Result<extended>
*/
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text) without rowid";
protected static $createTest = "CREATE TABLE arsse_test(id integer primary key)";

View file

@ -10,7 +10,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
* @covers \JKingWeb\Arsse\Db\SQLite3\Statement<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
public static function tearDownAfterClass() {
static::$interface->close();

View file

@ -10,7 +10,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
protected static $minimal1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
protected static $minimal2 = "pragma user_version=2";

View file

@ -11,7 +11,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3PDO;
* @covers \JKingWeb\Arsse\Misc\Query<extended>
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3PDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected function nextID(string $table): int {
return (int) static::$drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue();

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3PDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3PDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected $create = "CREATE TABLE arsse_test(id integer primary key)";
protected $lock = "BEGIN EXCLUSIVE TRANSACTION";

View file

@ -12,7 +12,7 @@ use JKingWeb\Arsse\Test\DatabaseInformation;
* @covers \JKingWeb\Arsse\Db\PDOResult<extended>
*/
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3PDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected static $createMeta = "CREATE TABLE arsse_meta(key text primary key not null, value text) without rowid";
protected static $createTest = "CREATE TABLE arsse_test(id integer primary key)";

View file

@ -11,7 +11,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3PDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3PDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected function makeStatement(string $q, array $types = []): array {
return [static::$interface, $q, $types];

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3PDO;
* @covers \JKingWeb\Arsse\Db\PDOError
* @covers \JKingWeb\Arsse\Db\SQLState */
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate {
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\SQLite3PDO;
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected static $minimal1 = "create table arsse_meta(key text primary key not null, value text); pragma user_version=1";
protected static $minimal2 = "pragma user_version=2";

View file

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;

View file

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;

View file

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;

View file

@ -4,10 +4,9 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;
trait PostgreSQLPDO {
protected static $implementation = "PDO PostgreSQL";

View file

@ -4,7 +4,7 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;

View file

@ -4,10 +4,9 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\DatabaseDrivers;
namespace JKingWeb\Arsse\Test\DatabaseDrivers;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\Driver;
trait SQLite3PDO {
protected static $implementation = "PDO SQLite 3";