Skip to content

Commit 2fdf937

Browse files
authored
Commands: use execute method, not run (#100)
* Commands: use execute method, not run * Add simple test
1 parent 5e2892b commit 2fdf937

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed

src/Command/MigrationCheckCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function configure(): void
4040
$this->setDescription('Check if entities are in sync with database and if migrations were executed');
4141
}
4242

43-
public function run(InputInterface $input, OutputInterface $output): int
43+
public function execute(InputInterface $input, OutputInterface $output): int
4444
{
4545
$exitCode = self::EXIT_OK;
4646
$exitCode |= $this->checkMigrationsExecuted($output);

src/Command/MigrationGenerateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function configure(): void
3131
$this->setDescription('Generate migration class');
3232
}
3333

34-
public function run(InputInterface $input, OutputInterface $output): int
34+
public function execute(InputInterface $input, OutputInterface $output): int
3535
{
3636
$sqls = $this->migrationService->generateDiffSqls();
3737

src/Command/MigrationInitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function configure(): void
3131
$this->setDescription('Create migration table in database');
3232
}
3333

34-
public function run(InputInterface $input, OutputInterface $output): int
34+
public function execute(InputInterface $input, OutputInterface $output): int
3535
{
3636
$output->write('<comment>Creating migration table... </comment>');
3737
$initialized = $this->migrationService->initializeMigrationTable();

src/Command/MigrationRunCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function configure(): void
4343
->addArgument(self::ARGUMENT_PHASE, InputArgument::REQUIRED, MigrationPhase::BEFORE . '|' . MigrationPhase::AFTER . '|' . self::PHASE_BOTH);
4444
}
4545

46-
public function run(InputInterface $input, OutputInterface $output): int
46+
public function execute(InputInterface $input, OutputInterface $output): int
4747
{
4848
$phaseArgument = $input->getArgument(self::ARGUMENT_PHASE);
4949

src/Command/MigrationSkipCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function configure(): void
3232
$this->setDescription('Mark all not executed migrations as executed in both phases');
3333
}
3434

35-
public function run(InputInterface $input, OutputInterface $output): int
35+
public function execute(InputInterface $input, OutputInterface $output): int
3636
{
3737
$skipped = false;
3838

tests/Command/MigrationRunCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ShipMonk\Doctrine\Migration\MigrationService;
1010
use Symfony\Component\Console\Input\ArrayInput;
1111
use Symfony\Component\Console\Output\BufferedOutput;
12+
use Symfony\Component\Console\Tester\CommandTester;
1213
use const PHP_EOL;
1314

1415
class MigrationRunCommandTest extends TestCase
@@ -72,6 +73,14 @@ public function testRunBoth(): void
7273
self::assertSame($output, $this->runPhase($command, MigrationRunCommand::PHASE_BOTH));
7374
}
7475

76+
public function testFailureNoArgs(): void
77+
{
78+
self::expectExceptionMessage('Not enough arguments (missing: "phase").');
79+
80+
$tester = new CommandTester(new MigrationRunCommand($this->createMock(MigrationService::class)));
81+
$tester->execute([]);
82+
}
83+
7584
private function runPhase(MigrationRunCommand $command, string $phase): string
7685
{
7786
$input = new ArrayInput([MigrationRunCommand::ARGUMENT_PHASE => $phase], $command->getDefinition());

0 commit comments

Comments
 (0)