From 26d22f10b8e4c3f5fad2ae2b00225c2b75c4cc40 Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Mon, 30 Jun 2025 11:41:12 +0200 Subject: [PATCH] UpdateRecipesCommand: add `--next` option --- src/Command/UpdateRecipesCommand.php | 10 ++++++++-- tests/Command/UpdateRecipesCommandTest.php | 13 +++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Command/UpdateRecipesCommand.php b/src/Command/UpdateRecipesCommand.php index 96d7d0d8f..5eb389e6f 100644 --- a/src/Command/UpdateRecipesCommand.php +++ b/src/Command/UpdateRecipesCommand.php @@ -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; @@ -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.') ; } @@ -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!'); @@ -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(); @@ -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; } } diff --git a/tests/Command/UpdateRecipesCommandTest.php b/tests/Command/UpdateRecipesCommandTest.php index efd16f547..c8c44f51f 100644 --- a/tests/Command/UpdateRecipesCommandTest.php +++ b/tests/Command/UpdateRecipesCommandTest.php @@ -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(); @@ -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()); @@ -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();