From 734704567e14f368f9bae359a42c45ddbe557339 Mon Sep 17 00:00:00 2001 From: Joelso Dias Date: Sun, 18 Apr 2021 21:59:42 -0300 Subject: [PATCH 1/3] Unify migration messages --- system/Database/MigrationRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index eeb204f4df09..46fbc03cd820 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -771,7 +771,7 @@ protected function removeHistory($history) if (is_cli()) { $this->cliMessages[] = "\t" . CLI::color(lang('Migrations.removed'), - 'yellow') . "($history->namespace) " . $history->version . '_' . $this->getMigrationName($history->class); + 'yellow') . "($history->namespace) " . $history->version . '_' . $history->class; } } From 4fb78fa534fbc117f46bb4f9d5f62bd86db6ee95 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 9 May 2021 17:15:26 +0800 Subject: [PATCH 2/3] Reformat message structuring --- system/Database/MigrationRunner.php | 35 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 46fbc03cd820..861fd729ca90 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -738,20 +738,24 @@ public function clearHistory() */ protected function addHistory($migration, int $batch) { - $this->db->table($this->table) - ->insert([ - 'version' => $migration->version, - 'class' => $migration->class, - 'group' => $this->group, - 'namespace' => $migration->namespace, - 'time' => time(), - 'batch' => $batch, - ]); + $this->db->table($this->table)->insert([ + 'version' => $migration->version, + 'class' => $migration->class, + 'group' => $this->group, + 'namespace' => $migration->namespace, + 'time' => time(), + 'batch' => $batch, + ]); if (is_cli()) { - $this->cliMessages[] = "\t" . CLI::color(lang('Migrations.added'), - 'yellow') . "($migration->namespace) " . $migration->version . '_' . $migration->class; + $this->cliMessages[] = sprintf( + "\t%s(%s) %s_%s", + CLI::color(lang('Migrations.added'), 'yellow'), + $migration->namespace, + $migration->version, + $migration->class + ); } } @@ -770,8 +774,13 @@ protected function removeHistory($history) if (is_cli()) { - $this->cliMessages[] = "\t" . CLI::color(lang('Migrations.removed'), - 'yellow') . "($history->namespace) " . $history->version . '_' . $history->class; + $this->cliMessages[] = sprintf( + "\t%s(%s) %s_%s", + CLI::color(lang('Migrations.removed'), 'yellow'), + $history->namespace, + $history->version, + $history->class + ); } } From 54095b5277f9fa9e9067f48905ea13a60383796a Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 9 May 2021 17:16:18 +0800 Subject: [PATCH 3/3] Add test to check if same name format --- .../Commands/MigrationIntegrationTest.php | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/system/Commands/MigrationIntegrationTest.php diff --git a/tests/system/Commands/MigrationIntegrationTest.php b/tests/system/Commands/MigrationIntegrationTest.php new file mode 100644 index 000000000000..a1e5442bf556 --- /dev/null +++ b/tests/system/Commands/MigrationIntegrationTest.php @@ -0,0 +1,76 @@ +migrationFileFrom)) + { + $this->fail(clean_path($this->migrationFileFrom) . ' is not found.'); + } + + if (is_file($this->migrationFileTo)) + { + @unlink($this->migrationFileTo); + } + + copy($this->migrationFileFrom, $this->migrationFileTo); + + $contents = file_get_contents($this->migrationFileTo); + $contents = str_replace('namespace Tests\Support\Database\Migrations;', 'namespace App\Database\Migrations;', $contents); + file_put_contents($this->migrationFileTo, $contents); + + CITestStreamFilter::$buffer = ''; + + $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter'); + $this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter'); + } + + protected function tearDown(): void + { + parent::tearDown(); + + if (is_file($this->migrationFileTo)) + { + @unlink($this->migrationFileTo); + } + + stream_filter_remove($this->streamFilter); + } + + /** + * @runTestsInSeparateProcesses + */ + public function testMigrationWithRollbackHasSameNameFormat(): void + { + command('migrate -n App'); + $this->assertStringContainsString( + '(App) 20160428212500_App\Database\Migrations\Migration_Create_test_tables', + CITestStreamFilter::$buffer + ); + + CITestStreamFilter::$buffer = ''; + + command('migrate:rollback -n App'); + $this->assertStringContainsString( + '(App) 20160428212500_App\Database\Migrations\Migration_Create_test_tables', + CITestStreamFilter::$buffer + ); + } +}