From a2b1ce28041ee6b3a6638901190610a19d3931ac Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 15 Nov 2023 18:02:08 +0800 Subject: [PATCH] Add failing test --- .../Migrations/MigrationRunnerTest.php | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/system/Database/Migrations/MigrationRunnerTest.php b/tests/system/Database/Migrations/MigrationRunnerTest.php index a573114c1f94..aac42778b9f8 100644 --- a/tests/system/Database/Migrations/MigrationRunnerTest.php +++ b/tests/system/Database/Migrations/MigrationRunnerTest.php @@ -12,7 +12,6 @@ namespace CodeIgniter\Database\Migrations; use CodeIgniter\Database\BaseConnection; -use CodeIgniter\Database\Config; use CodeIgniter\Database\MigrationRunner; use CodeIgniter\Events\Events; use CodeIgniter\Exceptions\ConfigException; @@ -454,11 +453,34 @@ public function testGetBatchVersions(): void $this->assertSame('2018-01-24-102302', $runner->getBatchEnd(1)); } - protected function resetTables(): void + public function testMigrationUsesSameConnectionAsMigrationRunner(): void { - $forge = Config::forge(); + $config = ['database' => WRITEPATH . 'runner.sqlite', 'DBDriver' => 'SQLite3', 'DBDebug' => true]; - foreach (db_connect()->listTables() as $table) { + $database = Database::connect($config, false); + $this->resetTables($database); + + $runner = new MigrationRunner(config(Migrations::class), $database); + $runner->clearCliMessages(); + $runner->clearHistory(); + $runner->setNamespace('Tests\Support\MigrationTestMigrations'); + $runner->latest(); + + $tables = $database->listTables(); + $this->assertCount(2, $tables); + $this->assertSame('migrations', $tables[0]); + $this->assertSame('foo', $tables[1]); + } + + protected function resetTables($db = null): void + { + $forge = Database::forge($db); + + /** @var BaseConnection $conn */ + $conn = $forge->getConnection(); + $conn->resetDataCache(); + + foreach (db_connect($db)->listTables() as $table) { $table = str_replace('db_', '', $table); $forge->dropTable($table, true); }