@@ -2,19 +2,39 @@
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
use CodeIgniter\Test\CIUnitTestCase;
|
||||
use Config\Database;
|
||||
use Throwable;
|
||||
|
||||
class DBReset
|
||||
{
|
||||
private const DB_GROUP = 'tests';
|
||||
|
||||
protected static array $excludeTables = ['migrations'];
|
||||
|
||||
public static function resetDatabase(): void
|
||||
{
|
||||
$db = Database::connect();
|
||||
$config = config('Database');
|
||||
$dbConfig = $config->{self::DB_GROUP} ?? [];
|
||||
|
||||
try {
|
||||
$db = Database::connect(self::DB_GROUP);
|
||||
$db->initialize();
|
||||
} catch (Throwable $exception) {
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
'Test database connection failed: group=%s host=%s port=%s database=%s',
|
||||
self::DB_GROUP,
|
||||
$dbConfig['hostname'] ?? '',
|
||||
$dbConfig['port'] ?? '',
|
||||
$dbConfig['database'] ?? ''
|
||||
),
|
||||
0,
|
||||
$exception
|
||||
);
|
||||
}
|
||||
|
||||
$db->disableForeignKeyChecks();
|
||||
|
||||
// Get all table names
|
||||
$tables = $db->listTables();
|
||||
|
||||
foreach ($tables as $table) {
|
||||
|
||||
Reference in New Issue
Block a user