Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ protected function migrate($direction, $migration): bool
throw new RuntimeException($message);
}

$instance = new $class();
/** @var Migration $instance */
$instance = new $class(Database::forge($this->db));
$group = $instance->getDBGroup() ?? config(Database::class)->defaultGroup;

if (ENVIRONMENT !== 'testing' && $group === 'tests' && $this->groupFilter !== 'tests') {
Expand Down
18 changes: 15 additions & 3 deletions system/ThirdParty/Escaper/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,21 @@ public function __construct(?string $encoding = null)
$this->htmlSpecialCharsFlags = ENT_QUOTES | ENT_SUBSTITUTE;

// set matcher callbacks
$this->htmlAttrMatcher = [$this, 'htmlAttrMatcher'];
$this->jsMatcher = [$this, 'jsMatcher'];
$this->cssMatcher = [$this, 'cssMatcher'];
$this->htmlAttrMatcher =
/** @param array<array-key, string> $matches */
function (array $matches): string {
return $this->htmlAttrMatcher($matches);
};
$this->jsMatcher =
/** @param array<array-key, string> $matches */
function (array $matches): string {
return $this->jsMatcher($matches);
};
$this->cssMatcher =
/** @param array<array-key, string> $matches */
function (array $matches): string {
return $this->cssMatcher($matches);
};
}

/**
Expand Down
31 changes: 27 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,35 @@ 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);
$conn = $forge->getConnection();
$conn->resetDataCache();
// d(config(Database::class));

foreach (db_connect($db)->listTables() as $table) {
// echo $conn->getLastQuery() . PHP_EOL;
// echo $table . PHP_EOL;
$table = str_replace('db_', '', $table);
$forge->dropTable($table, true);
}
Expand Down