Skip to content

Commit

Permalink
Show error when specified both path and namespace (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 14, 2023
1 parent 5e20ff5 commit e8427c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/Service/MigrationService.php
Expand Up @@ -60,7 +60,15 @@ public function before(string $defaultName): int
case 'migrate:create':
if (empty($this->createNamespace) && empty($this->createPath)) {
$this->io?->error(
'At least one of `createNamespace` or `createPath` should be specified.'
'One of `createNamespace` or `createPath` should be specified.'
);

$result = Command::INVALID;
}

if (!empty($this->createNamespace) && !empty($this->createPath)) {
$this->io?->error(
'Only one of `createNamespace` or `createPath` should be specified.'
);

$result = Command::INVALID;
Expand Down
41 changes: 39 additions & 2 deletions tests/Common/Command/AbstractCreateCommandTest.php
Expand Up @@ -1022,7 +1022,7 @@ public function testWithoutCreatePath(): void

$this->assertSame(Command::INVALID, $exitCode);
$this->assertStringContainsString(
'At least one of `createNamespace` or `createPath` should be specified.',
'One of `createNamespace` or `createPath` should be specified.',
$output
);
}
Expand Down Expand Up @@ -1058,7 +1058,44 @@ public function testWithoutCreateNamespace(): void

$this->assertSame(Command::INVALID, $exitCode);
$this->assertStringContainsString(
'At least one of `createNamespace` or `createPath` should be specified.',
'One of `createNamespace` or `createPath` should be specified.',
$output
);
}

public function testWithCreatePathAndNamespace(): void
{
MigrationHelper::useMigrationsPath($this->container);
MigrationHelper::useMigrationsNamespace($this->container);

$command = $this->createCommand($this->container);
$command->setInputs(['yes']);

$exitCode = $command->execute(['name' => 'post']);
$output = $command->getDisplay(true);

$this->assertSame(Command::INVALID, $exitCode);
$this->assertStringContainsString(
'Only one of `createNamespace` or `createPath` should be specified.',
$output
);
}

public function testWithOptionsPathAndNamespace(): void
{
$command = $this->createCommand($this->container);
$command->setInputs(['yes']);

$exitCode = $command->execute([
'name' => 'post',
'--path' => MigrationHelper::PATH_ALIAS,
'--namespace' => MigrationHelper::NAMESPACE,
]);
$output = $command->getDisplay(true);

$this->assertSame(Command::INVALID, $exitCode);
$this->assertStringContainsString(
'Only one of `createNamespace` or `createPath` should be specified.',
$output
);
}
Expand Down

0 comments on commit e8427c7

Please sign in to comment.