diff --git a/src/Console/Commands/ModuleMakeMigrationCommand.php b/src/Console/Commands/ModuleMakeMigrationCommand.php index b60b24a..7f0c5cf 100644 --- a/src/Console/Commands/ModuleMakeMigrationCommand.php +++ b/src/Console/Commands/ModuleMakeMigrationCommand.php @@ -59,7 +59,7 @@ public function handle() if ($create) { $arguments['--create'] = $this->getPluralName($create); - } else { + } elseif ($update) { $arguments['--table'] = $this->getPluralName($update); } diff --git a/tests/Commands/MakeMigrationCommandTest.php b/tests/Commands/MakeMigrationCommandTest.php new file mode 100644 index 0000000..d5c9a6f --- /dev/null +++ b/tests/Commands/MakeMigrationCommandTest.php @@ -0,0 +1,52 @@ +artisan( + command: 'module:make:migration', + parameters: [ + 'name' => 'create_posts_table', + '--module' => $this->moduleName, + ] + ) + ->assertSuccessful(); + + $this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'create_posts_table.php'); + } + + public function test_it_should_create_migration_file_with_create_option() + { + $this->artisan( + command: 'module:make:migration', + parameters: [ + 'name' => 'create_posts_table', + '--module' => $this->moduleName, + '--create' => 'posts', + ] + ) + ->assertSuccessful(); + + $this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'create_posts_table.php'); + } + + public function test_it_should_create_migration_file_with_table_option() + { + $this->artisan( + command: 'module:make:migration', + parameters: [ + 'name' => 'add_title_to_posts_table', + '--module' => $this->moduleName, + '--table' => 'posts', + ] + ) + ->assertSuccessful(); + + $this->assertMigrationFile(module: $this->moduleName, migrationFilename: 'add_title_to_posts_table.php'); + } +} diff --git a/tests/MakeCommandTestCase.php b/tests/MakeCommandTestCase.php index 29c07cd..a0abc29 100644 --- a/tests/MakeCommandTestCase.php +++ b/tests/MakeCommandTestCase.php @@ -43,8 +43,7 @@ public function cleanUp(): void protected function assertMigrationFile(string $module, string $migrationFilename): void { - $migrations = $this->files->allFiles(directory: $this->getModulePath($module)); - dd($migrations); + $migrations = $this->files->allFiles(directory: $this->getModulePath($module).'/Database/migrations'); $this->assertNotEmpty(actual: $migrations); $this->assertEquals( expected: 1,