Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Nov 16, 2023
1 parent 71a461e commit a2b1ce2
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tests/system/Database/Migrations/MigrationRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a2b1ce2

Please sign in to comment.