|
12 | 12 | namespace CodeIgniter\Database\Migrations; |
13 | 13 |
|
14 | 14 | use CodeIgniter\Database\BaseConnection; |
15 | | -use CodeIgniter\Database\Config; |
16 | 15 | use CodeIgniter\Database\MigrationRunner; |
17 | 16 | use CodeIgniter\Events\Events; |
18 | 17 | use CodeIgniter\Exceptions\ConfigException; |
@@ -454,11 +453,34 @@ public function testGetBatchVersions(): void |
454 | 453 | $this->assertSame('2018-01-24-102302', $runner->getBatchEnd(1)); |
455 | 454 | } |
456 | 455 |
|
457 | | - protected function resetTables(): void |
| 456 | + public function testMigrationUsesSameConnectionAsMigrationRunner(): void |
458 | 457 | { |
459 | | - $forge = Config::forge(); |
| 458 | + $config = ['database' => WRITEPATH . 'runner.sqlite', 'DBDriver' => 'SQLite3', 'DBDebug' => true]; |
460 | 459 |
|
461 | | - foreach (db_connect()->listTables() as $table) { |
| 460 | + $database = Database::connect($config, false); |
| 461 | + $this->resetTables($database); |
| 462 | + |
| 463 | + $runner = new MigrationRunner(config(Migrations::class), $database); |
| 464 | + $runner->clearCliMessages(); |
| 465 | + $runner->clearHistory(); |
| 466 | + $runner->setNamespace('Tests\Support\MigrationTestMigrations'); |
| 467 | + $runner->latest(); |
| 468 | + |
| 469 | + $tables = $database->listTables(); |
| 470 | + $this->assertCount(2, $tables); |
| 471 | + $this->assertSame('migrations', $tables[0]); |
| 472 | + $this->assertSame('foo', $tables[1]); |
| 473 | + } |
| 474 | + |
| 475 | + protected function resetTables($db = null): void |
| 476 | + { |
| 477 | + $forge = Database::forge($db); |
| 478 | + |
| 479 | + /** @var BaseConnection $conn */ |
| 480 | + $conn = $forge->getConnection(); |
| 481 | + $conn->resetDataCache(); |
| 482 | + |
| 483 | + foreach (db_connect($db)->listTables() as $table) { |
462 | 484 | $table = str_replace('db_', '', $table); |
463 | 485 | $forge->dropTable($table, true); |
464 | 486 | } |
|
0 commit comments