Skip to content

UpdateRecipesCommand: add --next option #1059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Command/UpdateRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Flex\Configurator;
use Symfony\Flex\Downloader;
Expand Down Expand Up @@ -57,6 +58,7 @@ protected function configure()
->setAliases(['recipes:update'])
->setDescription('Updates an already-installed recipe to the latest version.')
->addArgument('package', InputArgument::OPTIONAL, 'Recipe that should be updated.')
->addOption('next', null, InputOption::VALUE_NONE, 'Update recipe of next outdated package.')
;
}

Expand All @@ -81,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$packageName = $input->getArgument('package');
$symfonyLock = $this->flex->getLock();
if (!$packageName) {
$packageName = $this->askForPackage($io, $symfonyLock);
$packageName = $this->getNextOrAskForPackage($io, $symfonyLock, $input->getOption('next'));

if (null === $packageName) {
$io->writeError('All packages appear to be up-to-date!');
Expand Down Expand Up @@ -353,7 +355,7 @@ private function generateChangelog(Recipe $originalRecipe): ?array
return $lines;
}

private function askForPackage(IOInterface $io, Lock $symfonyLock): ?string
private function getNextOrAskForPackage(IOInterface $io, Lock $symfonyLock, bool $next = false): ?string
{
$installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();

Expand All @@ -373,6 +375,10 @@ private function askForPackage(IOInterface $io, Lock $symfonyLock): ?string
$lockRef = $symfonyLock->get($name)['recipe']['ref'] ?? null;

if (null !== $lockRef && $recipe->getRef() !== $lockRef && !$recipe->isAuto()) {
if ($next) {
return $name;
}

$outdatedRecipes[] = $name;
}
}
Expand Down
13 changes: 11 additions & 2 deletions tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ protected function tearDown(): void
* that we can easily use to assert.
*
* @requires PHP >= 7.2
* @dataProvider provideCommandInput
*/
public function testCommandUpdatesRecipe()
public function testCommandUpdatesRecipe(array $input)
{
@mkdir(FLEX_TEST_DIR);
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
Expand All @@ -78,7 +79,7 @@ public function testCommandUpdatesRecipe()
(new Process([__DIR__.'/../../vendor/bin/composer', 'install'], FLEX_TEST_DIR))->mustRun();

$command = $this->createCommandUpdateRecipes();
$command->execute(['package' => 'symfony/console']);
$command->execute($input);

$this->assertSame(0, $command->getStatusCode());
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
Expand All @@ -88,6 +89,14 @@ public function testCommandUpdatesRecipe()
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
}

public function provideCommandInput()
{
return [
[['package' => 'symfony/console']],
[['--next' => true]],
];
}

private function createCommandUpdateRecipes(): CommandTester
{
$this->io = new BufferIO();
Expand Down
Loading