diff --git a/src/Console/Commands/LiftMigration.php b/src/Console/Commands/LiftMigration.php index 128854e..d89aed9 100644 --- a/src/Console/Commands/LiftMigration.php +++ b/src/Console/Commands/LiftMigration.php @@ -29,7 +29,7 @@ final class LiftMigration extends Command public function handle(): int { try { - $class = $this->option('namespace') . '\\' . $this->argument('model'); // @phpstan-ignore-line + $class = rtrim($this->option('namespace'), '\\') . '\\' . $this->argument('model'); // @phpstan-ignore-line if (! class_exists($class)) { $this->error("Model {$class} not found."); diff --git a/tests/Feature/LiftMigrationTest.php b/tests/Feature/LiftMigrationTest.php index 4b89a3e..d963e5c 100644 --- a/tests/Feature/LiftMigrationTest.php +++ b/tests/Feature/LiftMigrationTest.php @@ -13,6 +13,17 @@ unlink($migrationClass); }); + + it('generates a migration file for a model if namespace ends with slash', function () { + $migrationClass = database_path('migrations/' . date('Y_m_d_His') . '_create_users_migration_table.php'); + + $this->artisan('lift:migration UserMigration --namespace=Tests\\\Datasets\\') + ->assertExitCode(0); + + expect($migrationClass)->toBeFileWithContent(UserMigrationCreate()); + + unlink($migrationClass); + }); }); describe('UPDATE TABLE', function () { @@ -26,6 +37,17 @@ unlink($migrationClass); }); + + it('generates a migration file for a model adding and dropping columns if namespace ends with slash', function () { + $migrationClass = database_path('migrations/' . date('Y_m_d_His') . '_update_users_migrated_table.php'); + + $this->artisan('lift:migration UserMigratedUpdateTable --namespace=Tests\\\Datasets\\') + ->assertExitCode(0); + + expect($migrationClass)->toBeFileWithContent(UserMigrationAddColumns()); + + unlink($migrationClass); + }); }); function UserMigrationCreate(): string