J. King
2 years ago
28 changed files with 1419 additions and 1020 deletions
@ -0,0 +1,60 @@ |
|||||
|
<?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\Test\DatabaseDrivers; |
||||
|
|
||||
|
use JKingWeb\Arsse\Db\Driver; |
||||
|
|
||||
|
trait MySQLCommon { |
||||
|
public static function dbTableList($db): array { |
||||
|
$listTables = "SELECT table_name as name from information_schema.tables where table_schema = database() and table_name like 'arsse_%'"; |
||||
|
if ($db instanceof Driver) { |
||||
|
$tables = $db->query($listTables)->getAll(); |
||||
|
} elseif ($db instanceof \PDO) { |
||||
|
$tables = $db->query($listTables)->fetchAll(\PDO::FETCH_ASSOC); |
||||
|
} else { |
||||
|
$tables = $db->query($listTables)->fetch_all(\MYSQLI_ASSOC); |
||||
|
} |
||||
|
$tables = sizeof($tables) ? array_column($tables, "name") : []; |
||||
|
return $tables; |
||||
|
} |
||||
|
|
||||
|
public static function dbTruncate($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
$db->query("UNLOCK TABLES; ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
$db->query("SET FOREIGN_KEY_CHECKS=0"); |
||||
|
foreach (self::dbTableList($db) as $table) { |
||||
|
if ($table === "arsse_meta") { |
||||
|
$db->query("DELETE FROM $table where `key` <> 'schema_version'"); |
||||
|
} else { |
||||
|
$db->query("TRUNCATE TABLE $table"); |
||||
|
} |
||||
|
} |
||||
|
foreach ($afterStatements as $st) { |
||||
|
$db->query($st); |
||||
|
} |
||||
|
$db->query("SET FOREIGN_KEY_CHECKS=1"); |
||||
|
} |
||||
|
|
||||
|
public static function dbRaze($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
$db->query("UNLOCK TABLES; ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
$db->query("SET FOREIGN_KEY_CHECKS=0"); |
||||
|
foreach (self::dbTableList($db) as $table) { |
||||
|
$db->query("DROP TABLE IF EXISTS $table"); |
||||
|
} |
||||
|
foreach ($afterStatements as $st) { |
||||
|
$db->query($st); |
||||
|
} |
||||
|
$db->query("SET FOREIGN_KEY_CHECKS=1"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
<?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\Test\DatabaseDrivers; |
||||
|
|
||||
|
use JKingWeb\Arsse\Db\Driver; |
||||
|
|
||||
|
trait PostgreSQLCommon { |
||||
|
public static function dbExec($db, $q): void { |
||||
|
if ($db instanceof Driver) { |
||||
|
$db->exec($q); |
||||
|
} elseif ($db instanceof \PDO) { |
||||
|
$db->exec($q); |
||||
|
} else { |
||||
|
pg_query($db, $q); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static function dbTableList($db): array { |
||||
|
$listObjects = "SELECT table_name as name, 'TABLE' as type from information_schema.tables where table_schema = current_schema() and table_name like 'arsse_%' union SELECT collation_name as name, 'COLLATION' as type from information_schema.collations where collation_schema = current_schema()"; |
||||
|
if ($db instanceof Driver) { |
||||
|
return $db->query($listObjects)->getAll(); |
||||
|
} elseif ($db instanceof \PDO) { |
||||
|
return $db->query($listObjects)->fetchAll(\PDO::FETCH_ASSOC); |
||||
|
} else { |
||||
|
$r = @pg_query($db, $listObjects); |
||||
|
$out = $r ? pg_fetch_all($r) : false; |
||||
|
return $out ? $out : []; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static function dbTruncate($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
@self::dbExec($db, "ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
foreach (self::dbTableList($db) as $obj) { |
||||
|
if ($obj['type'] !== "TABLE") { |
||||
|
continue; |
||||
|
} elseif ($obj['name'] === "arsse_meta") { |
||||
|
self::dbExec($db, "DELETE FROM {$obj['name']} where key <> 'schema_version'"); |
||||
|
} else { |
||||
|
self::dbExec($db, "TRUNCATE TABLE {$obj['name']} restart identity cascade"); |
||||
|
} |
||||
|
} |
||||
|
foreach ($afterStatements as $st) { |
||||
|
self::dbExec($db, $st); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static function dbRaze($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
@self::dbExec($db, "ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
foreach (self::dbTableList($db) as $obj) { |
||||
|
self::dbExec($db, "DROP {$obj['type']} IF EXISTS {$obj['name']} cascade"); |
||||
|
} |
||||
|
foreach ($afterStatements as $st) { |
||||
|
self::dbExec($db, $st); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
<?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\Test\DatabaseDrivers; |
||||
|
|
||||
|
use JKingWeb\Arsse\Db\Driver; |
||||
|
|
||||
|
trait SQLite3Common { |
||||
|
public static function dbTableList($db): array { |
||||
|
$listTables = "SELECT name from sqlite_master where type = 'table' and name like 'arsse^_%' escape '^'"; |
||||
|
if ($db instanceof Driver) { |
||||
|
$tables = $db->query($listTables)->getAll(); |
||||
|
$tables = sizeof($tables) ? array_column($tables, "name") : []; |
||||
|
} elseif ($db instanceof \PDO) { |
||||
|
retry: |
||||
|
try { |
||||
|
$tables = $db->query($listTables)->fetchAll(\PDO::FETCH_ASSOC); |
||||
|
} catch (\PDOException $e) { |
||||
|
goto retry; |
||||
|
} |
||||
|
$tables = sizeof($tables) ? array_column($tables, "name") : []; |
||||
|
} else { |
||||
|
$tables = []; |
||||
|
$result = $db->query($listTables); |
||||
|
while ($r = $result->fetchArray(\SQLITE3_ASSOC)) { |
||||
|
$tables[] = $r['name']; |
||||
|
} |
||||
|
$result->finalize(); |
||||
|
} |
||||
|
return $tables; |
||||
|
} |
||||
|
|
||||
|
public static function dbTruncate($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
$db->exec("ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
foreach (self::dbTableList($db) as $table) { |
||||
|
if ($table === "arsse_meta") { |
||||
|
$db->exec("DELETE FROM $table where key <> 'schema_version'"); |
||||
|
} else { |
||||
|
$db->exec("DELETE FROM $table"); |
||||
|
} |
||||
|
} |
||||
|
foreach ($afterStatements as $st) { |
||||
|
$db->exec($st); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public static function dbRaze($db, array $afterStatements = []): void { |
||||
|
// rollback any pending transaction |
||||
|
try { |
||||
|
$db->exec("ROLLBACK"); |
||||
|
} catch (\Throwable $e) { |
||||
|
} |
||||
|
$db->exec("PRAGMA foreign_keys=0"); |
||||
|
foreach (self::dbTableList($db) as $table) { |
||||
|
$db->exec("DROP TABLE IF EXISTS $table"); |
||||
|
} |
||||
|
$db->exec("PRAGMA user_version=0"); |
||||
|
$db->exec("PRAGMA foreign_keys=1"); |
||||
|
foreach ($afterStatements as $st) { |
||||
|
$db->exec($st); |
||||
|
} |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"require-dev": { |
||||
|
"phpstan/phpstan": "^0.12.99" |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
{ |
||||
|
"_readme": [ |
||||
|
"This file locks the dependencies of your project to a known state", |
||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |
||||
|
"This file is @generated automatically" |
||||
|
], |
||||
|
"content-hash": "b260ae3dc51b5d4100c545bf9e65f543", |
||||
|
"packages": [], |
||||
|
"packages-dev": [ |
||||
|
{ |
||||
|
"name": "phpstan/phpstan", |
||||
|
"version": "0.12.99", |
||||
|
"source": { |
||||
|
"type": "git", |
||||
|
"url": "https://github.com/phpstan/phpstan.git", |
||||
|
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7" |
||||
|
}, |
||||
|
"dist": { |
||||
|
"type": "zip", |
||||
|
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7", |
||||
|
"reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7", |
||||
|
"shasum": "" |
||||
|
}, |
||||
|
"require": { |
||||
|
"php": "^7.1|^8.0" |
||||
|
}, |
||||
|
"conflict": { |
||||
|
"phpstan/phpstan-shim": "*" |
||||
|
}, |
||||
|
"bin": [ |
||||
|
"phpstan", |
||||
|
"phpstan.phar" |
||||
|
], |
||||
|
"type": "library", |
||||
|
"extra": { |
||||
|
"branch-alias": { |
||||
|
"dev-master": "0.12-dev" |
||||
|
} |
||||
|
}, |
||||
|
"autoload": { |
||||
|
"files": [ |
||||
|
"bootstrap.php" |
||||
|
] |
||||
|
}, |
||||
|
"notification-url": "https://packagist.org/downloads/", |
||||
|
"license": [ |
||||
|
"MIT" |
||||
|
], |
||||
|
"description": "PHPStan - PHP Static Analysis Tool", |
||||
|
"support": { |
||||
|
"issues": "https://github.com/phpstan/phpstan/issues", |
||||
|
"source": "https://github.com/phpstan/phpstan/tree/0.12.99" |
||||
|
}, |
||||
|
"funding": [ |
||||
|
{ |
||||
|
"url": "https://github.com/ondrejmirtes", |
||||
|
"type": "github" |
||||
|
}, |
||||
|
{ |
||||
|
"url": "https://github.com/phpstan", |
||||
|
"type": "github" |
||||
|
}, |
||||
|
{ |
||||
|
"url": "https://www.patreon.com/phpstan", |
||||
|
"type": "patreon" |
||||
|
}, |
||||
|
{ |
||||
|
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", |
||||
|
"type": "tidelift" |
||||
|
} |
||||
|
], |
||||
|
"time": "2021-09-12T20:09:55+00:00" |
||||
|
} |
||||
|
], |
||||
|
"aliases": [], |
||||
|
"minimum-stability": "stable", |
||||
|
"stability-flags": [], |
||||
|
"prefer-stable": false, |
||||
|
"prefer-lowest": false, |
||||
|
"platform": [], |
||||
|
"platform-dev": [], |
||||
|
"plugin-api-version": "2.2.0" |
||||
|
} |
File diff suppressed because it is too large
Loading…
Reference in new issue