Skip to content

Commit

Permalink
Commands: use execute method, not run (#100)
Browse files Browse the repository at this point in the history
* Commands: use execute method, not run

* Add simple test
  • Loading branch information
janedbal authored Oct 2, 2024
1 parent 5e2892b commit 2fdf937
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Command/MigrationCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function configure(): void
$this->setDescription('Check if entities are in sync with database and if migrations were executed');
}

public function run(InputInterface $input, OutputInterface $output): int
public function execute(InputInterface $input, OutputInterface $output): int
{
$exitCode = self::EXIT_OK;
$exitCode |= $this->checkMigrationsExecuted($output);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MigrationGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function configure(): void
$this->setDescription('Generate migration class');
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Command/MigrationInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function configure(): void
$this->setDescription('Create migration table in database');
}

public function run(InputInterface $input, OutputInterface $output): int
public function execute(InputInterface $input, OutputInterface $output): int
{
$output->write('<comment>Creating migration table... </comment>');
$initialized = $this->migrationService->initializeMigrationTable();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MigrationRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure(): void
->addArgument(self::ARGUMENT_PHASE, InputArgument::REQUIRED, MigrationPhase::BEFORE . '|' . MigrationPhase::AFTER . '|' . self::PHASE_BOTH);
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Command/MigrationSkipCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function configure(): void
$this->setDescription('Mark all not executed migrations as executed in both phases');
}

public function run(InputInterface $input, OutputInterface $output): int
public function execute(InputInterface $input, OutputInterface $output): int
{
$skipped = false;

Expand Down
9 changes: 9 additions & 0 deletions tests/Command/MigrationRunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ShipMonk\Doctrine\Migration\MigrationService;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Tester\CommandTester;
use const PHP_EOL;

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

public function testFailureNoArgs(): void
{
self::expectExceptionMessage('Not enough arguments (missing: "phase").');

$tester = new CommandTester(new MigrationRunCommand($this->createMock(MigrationService::class)));
$tester->execute([]);
}

private function runPhase(MigrationRunCommand $command, string $phase): string
{
$input = new ArrayInput([MigrationRunCommand::ARGUMENT_PHASE => $phase], $command->getDefinition());
Expand Down

0 comments on commit 2fdf937

Please sign in to comment.