@@ -454,11 +454,34 @@ public function testGetBatchVersions(): void
454454 $ this ->assertSame ('2018-01-24-102302 ' , $ runner ->getBatchEnd (1 ));
455455 }
456456
457- protected function resetTables (): void
457+ /**
458+ * @runInSeparateProcess
459+ * @preserveGlobalState disabled
460+ */
461+ public function testMigrationUsesSameConnectionAsMigrationRunner (): void
458462 {
459- $ forge = Config:: forge () ;
463+ $ config = [ ' database ' => WRITEPATH . ' runner.sqlite ' , ' DBDriver ' => ' SQLite3 ' , ' DBDebug ' => true ] ;
460464
461- foreach (db_connect ()->listTables () as $ table ) {
465+ $ database = Database::connect ($ config , false );
466+ $ this ->resetTables ($ database );
467+
468+ $ runner = new MigrationRunner (config (Migrations::class), $ database );
469+ $ runner ->clearCliMessages ();
470+ $ runner ->clearHistory ();
471+ $ runner ->setNamespace ('Tests\Support\MigrationTestMigrations ' );
472+ $ runner ->latest ();
473+
474+ $ tables = $ database ->listTables ();
475+ $ this ->assertCount (2 , $ tables );
476+ $ this ->assertSame ('migrations ' , $ tables [0 ]);
477+ $ this ->assertSame ('foo ' , $ tables [1 ]);
478+ }
479+
480+ protected function resetTables ($ db = null ): void
481+ {
482+ $ forge = Database::forge ($ db );
483+
484+ foreach (db_connect ($ db )->listTables () as $ table ) {
462485 $ table = str_replace ('db_ ' , '' , $ table );
463486 $ forge ->dropTable ($ table , true );
464487 }
0 commit comments