diff --git a/src/Command/UpdateRecipesCommand.php b/src/Command/UpdateRecipesCommand.php index 96d7d0d8..5eb389e6 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 efd16f54..c8c44f51 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();