Skip to content

Commit

Permalink
Merge pull request #85 from BadJacky/bugfix/fix-namespace-concatenati…
Browse files Browse the repository at this point in the history
…on-with-duplicate-slash

Fixing Namespace Option Ending with Backslash in LiftMigration Command
  • Loading branch information
WendellAdriel committed May 28, 2024
2 parents 32a3aad + 2e593f2 commit 1c3b292
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Console/Commands/LiftMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
22 changes: 22 additions & 0 deletions tests/Feature/LiftMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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
Expand Down

0 comments on commit 1c3b292

Please sign in to comment.