Skip to content

Commit

Permalink
SelfUpdateCommand - fix link to UPGRADE docs
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Aug 16, 2021
1 parent 4d09930 commit c1c011e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Console/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
&& true !== $input->getOption('force')
) {
$output->writeln(sprintf('<info>A new major version of PHP CS Fixer is available</info> (<comment>%s</comment>)', $latestVersion));
$output->writeln(sprintf('<info>Before upgrading please read</info> https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $latestVersion));
$output->writeln(sprintf('<info>Before upgrading please read</info> https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE-v%s.md', $latestVersion, $currentMajor + 1));
$output->writeln('<info>If you are ready to upgrade run this command with</info> <comment>-f</comment>');
$output->writeln('<info>Checking for new minor/patch version...</info>');

Expand Down
70 changes: 38 additions & 32 deletions tests/Console/Command/SelfUpdateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected function doSetUp()

file_put_contents($this->getToolPath(), 'Current PHP CS Fixer.');

file_put_contents("{$this->root->url()}/{$this->getNewMinorVersion()}.phar", 'New minor version of PHP CS Fixer.');
file_put_contents("{$this->root->url()}/{$this->getNewMajorVersion()}.phar", 'New major version of PHP CS Fixer.');
file_put_contents("{$this->root->url()}/{$this->getNewMinorReleaseVersion()}.phar", 'New minor version of PHP CS Fixer.');
file_put_contents("{$this->root->url()}/{$this->getNewMajorReleaseVersion()}.phar", 'New major version of PHP CS Fixer.');
}

protected function doTearDown()
Expand Down Expand Up @@ -141,30 +141,31 @@ public function testExecute(
public function provideExecuteCases()
{
$currentVersion = Application::VERSION;
$minor = $this->getNewMinorVersion();
$minorRelease = $this->getNewMinorReleaseVersion();
$majorRelease = $this->getNewMajorReleaseVersion();
$major = $this->getNewMajorVersion();

$currentContents = 'Current PHP CS Fixer.';
$minorContents = 'New minor version of PHP CS Fixer.';
$majorContents = 'New major version of PHP CS Fixer.';

$upToDateDisplay = "\033[32mPHP CS Fixer is already up to date.\033[39m\n";
$newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)\n";
$newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$major}\033[39m)\n";
$newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m)\n";
$newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$majorRelease}\033[39m)\n";
$majorInfoNoMinorDisplay = <<<OUTPUT
\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$major}\033[39m)
\033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$major}/UPGRADE.md
\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$majorRelease}\033[39m)
\033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$majorRelease}/UPGRADE-v{$major}.md
\033[32mIf you are ready to upgrade run this command with\033[39m \033[33m-f\033[39m
\033[32mChecking for new minor/patch version...\033[39m
\033[32mNo minor update for PHP CS Fixer.\033[39m
OUTPUT;
$majorInfoNewMinorDisplay = <<<OUTPUT
\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$major}\033[39m)
\033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$major}/UPGRADE.md
\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$majorRelease}\033[39m)
\033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$majorRelease}/UPGRADE-v{$major}.md
\033[32mIf you are ready to upgrade run this command with\033[39m \033[33m-f\033[39m
\033[32mChecking for new minor/patch version...\033[39m
\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)
\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m)
OUTPUT;

Expand All @@ -178,28 +179,28 @@ public function provideExecuteCases()
[Application::VERSION, Application::VERSION, ['-f' => true], false, $currentContents, $upToDateDisplay],

// new minor version available
[$minor, $minor, [], true, $minorContents, $newMinorDisplay],
[$minor, $minor, ['--force' => true], true, $minorContents, $newMinorDisplay],
[$minor, $minor, ['-f' => true], true, $minorContents, $newMinorDisplay],
[$minor, $minor, [], false, $minorContents, $newMinorDisplay],
[$minor, $minor, ['--force' => true], false, $minorContents, $newMinorDisplay],
[$minor, $minor, ['-f' => true], false, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, [], true, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, ['--force' => true], true, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, ['-f' => true], true, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, [], false, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, ['--force' => true], false, $minorContents, $newMinorDisplay],
[$minorRelease, $minorRelease, ['-f' => true], false, $minorContents, $newMinorDisplay],

// new major version available
[$major, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay],
[$major, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay],
[$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$majorRelease, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay],
[$majorRelease, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay],
[$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay],

// new minor version and new major version available
[$major, $minor, [], true, $minorContents, $majorInfoNewMinorDisplay],
[$major, $minor, [], false, $minorContents, $majorInfoNewMinorDisplay],
[$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$majorRelease, $minorRelease, [], true, $minorContents, $majorInfoNewMinorDisplay],
[$majorRelease, $minorRelease, [], false, $minorContents, $majorInfoNewMinorDisplay],
[$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay],
[$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay],
[$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay],

// weird/unexpected versions
['v0.1.0', 'v0.1.0', [], true, $currentContents, $upToDateDisplay],
Expand Down Expand Up @@ -244,7 +245,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions(
) {
$versionChecker = $this->prophesize(\PhpCsFixer\Console\SelfUpdate\NewVersionCheckerInterface::class);

$newMajorVersion = $this->getNewMajorVersion();
$newMajorVersion = $this->getNewMajorReleaseVersion();
$versionChecker->getLatestVersion()->will(function () use ($latestVersionSuccess, $newMajorVersion) {
if ($latestVersionSuccess) {
return $newMajorVersion;
Expand All @@ -253,7 +254,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions(
throw new \RuntimeException('Foo.');
});

$newMinorVersion = $this->getNewMinorVersion();
$newMinorVersion = $this->getNewMinorReleaseVersion();
$versionChecker
->getLatestVersionOfMajor($this->getCurrentMajorVersion())
->will(function () use ($latestMinorVersionSuccess, $newMinorVersion) {
Expand Down Expand Up @@ -400,13 +401,18 @@ private function getCurrentMajorVersion()
return (int) preg_replace('/^v?(\d+).*$/', '$1', Application::VERSION);
}

private function getNewMinorVersion()
private function getNewMinorReleaseVersion()
{
return "{$this->getCurrentMajorVersion()}.999.0";
}

private function getNewMajorVersion()
{
return ($this->getCurrentMajorVersion() + 1).'.0.0';
return $this->getCurrentMajorVersion() + 1;
}

private function getNewMajorReleaseVersion()
{
return $this->getNewMajorVersion().'.0.0';
}
}

0 comments on commit c1c011e

Please sign in to comment.