Skip to content

Commit 1dfb334

Browse files
authored
Merge pull request #20 from bstanley-pec/feat/add-migrate-fresh-command-post-hook
Added migrate:fresh to array of commands after which migrate:dump will automatically run
2 parents 0c7ad26 + 32c28f6 commit 1dfb334

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Handlers/MigrateFinishedHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class MigrateFinishedHandler
1111
public function handle(CommandFinished $event)
1212
{
1313
if (
14-
// CONSIDER: Also `migrate:fresh`.
15-
in_array($event->command, ['migrate', 'migrate:rollback'], true)
14+
in_array($event->command, ['migrate', 'migrate:fresh', 'migrate:rollback'], true)
1615
&& ! $event->input->hasParameterOption(['--help', '--pretend', '-V', '--version'])
1716
&& config('migration-snapshot.dump', true)
1817
&& in_array(app()->environment(), explode(',', config('migration-snapshot.environments')), true)

tests/MigrateHookTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ public function test_handle()
2828
$this->assertStringContainsString('Dumped schema', $output_string);
2929
}
3030

31+
public function test_handle_dumpsOnFresh()
32+
{
33+
$this->createTestTablesWithoutMigrate();
34+
35+
$output = new BufferedOutput();
36+
$result = \Artisan::call('migrate:fresh',
37+
[
38+
'--path' => realpath(__DIR__ . '/migrations/setup'),
39+
'--realpath' => true,
40+
],
41+
$output
42+
);
43+
$this->assertEquals(0, $result);
44+
45+
$output_string = $output->fetch();
46+
$this->assertStringContainsString('Dumped schema', $output_string);
47+
}
48+
3149
public function test_handle_dumpsOnRollback()
3250
{
3351
$this->createTestTablesWithoutMigrate();

0 commit comments

Comments
 (0)