Skip to content

Commit

Permalink
Merge pull request doctrine#988 from oat-sa/fix-latest-version
Browse files Browse the repository at this point in the history
Re-enable alpha1 meaningful message when "latest" already reached.
  • Loading branch information
goetas committed Jun 20, 2020
1 parent bfbdb33 commit 8945504
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
19 changes: 14 additions & 5 deletions lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,20 @@ private function errorForAlias(string $versionAlias, bool $allowNoMigration) : i
if (in_array($versionAlias, ['first', 'next', 'latest'], true) || strpos($versionAlias, 'current') === 0) {
$version = $this->getDependencyFactory()->getVersionAliasResolver()->resolveVersionAlias('current');

$message = sprintf(
'The version "%s" couldn\'t be reached, you are at version "%s"',
$versionAlias,
(string) $version
);
// Allow meaningful message when latest version already reached.
if ($versionAlias === 'next' || $versionAlias === 'latest') {
$message = sprintf(
'Already at "%s" version ("%s")',
$versionAlias,
(string) $version
);
} else {
$message = sprintf(
'The version "%s" couldn\'t be reached, you are at version "%s"',
$versionAlias,
(string) $version
);
}

if ($allowNoMigration) {
$this->io->warning($message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Tester\CommandTester;
use function getcwd;
use function in_array;
use function sprintf;
use function strpos;
use function trim;
Expand Down Expand Up @@ -121,15 +122,25 @@ public function testExecuteAtVersion(string $targetAlias, bool $allowNoMigration
['interactive' => false]
);

$display = trim($this->migrateCommandTester->getDisplay(true));
$aliases = ['next', 'latest'];

if (in_array($targetAlias, $aliases, true)) {
$message = '[%s] Already at "%s" version ("%s")';
} else {
$message = '[%s] The version "%s" couldn\'t be reached, you are at version "%s"';
}

self::assertStringContainsString(
trim($this->migrateCommandTester->getDisplay(true)),
$display,
sprintf(
'[%s] The version "%s" couldn\'t be reached, you are at version "%s"',
$message,
($allowNoMigration ? 'WARNING' : 'ERROR'),
$targetAlias,
($executedMigration ?? '0')
)
);

self::assertSame($allowNoMigration ? 0 : 1, $this->migrateCommandTester->getStatusCode());
}

Expand Down

0 comments on commit 8945504

Please sign in to comment.