29 lines
586 B
PHP
29 lines
586 B
PHP
<?php
|
|
|
|
namespace Tests\Support;
|
|
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
use Config\Database;
|
|
|
|
class DBReset
|
|
{
|
|
protected static array $excludeTables = ['migrations'];
|
|
|
|
public static function resetDatabase(): void
|
|
{
|
|
$db = Database::connect();
|
|
$db->disableForeignKeyChecks();
|
|
|
|
// Get all table names
|
|
$tables = $db->listTables();
|
|
|
|
foreach ($tables as $table) {
|
|
if (!in_array($table, self::$excludeTables)) {
|
|
$db->table($table)->truncate();
|
|
}
|
|
}
|
|
|
|
$db->enableForeignKeyChecks();
|
|
}
|
|
}
|