Skip to content

Commit af3a64b

Browse files
committed
UpdateRecipesCommand: add --next option
1 parent 6479b0a commit af3a64b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/Command/UpdateRecipesCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Exception\RuntimeException;
2020
use Symfony\Component\Console\Input\InputArgument;
2121
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Input\InputOption;
2223
use Symfony\Component\Console\Output\OutputInterface;
2324
use Symfony\Flex\Configurator;
2425
use Symfony\Flex\Downloader;
@@ -57,6 +58,7 @@ protected function configure()
5758
->setAliases(['recipes:update'])
5859
->setDescription('Updates an already-installed recipe to the latest version.')
5960
->addArgument('package', InputArgument::OPTIONAL, 'Recipe that should be updated.')
61+
->addOption('next', null, InputOption::VALUE_NONE, 'Update recipe of next outdated package.')
6062
;
6163
}
6264

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

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

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

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

375377
if (null !== $lockRef && $recipe->getRef() !== $lockRef && !$recipe->isAuto()) {
378+
if ($next) {
379+
return $name;
380+
}
381+
376382
$outdatedRecipes[] = $name;
377383
}
378384
}

tests/Command/UpdateRecipesCommandTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ protected function tearDown(): void
5757
* that we can easily use to assert.
5858
*
5959
* @requires PHP >= 7.2
60+
* @dataProvider provideCommandInput
6061
*/
61-
public function testCommandUpdatesRecipe()
62+
public function testCommandUpdatesRecipe(array $input)
6263
{
6364
@mkdir(FLEX_TEST_DIR);
6465
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
@@ -75,10 +76,10 @@ public function testCommandUpdatesRecipe()
7576
(new Process(['git', 'add', '-A'], FLEX_TEST_DIR))->mustRun();
7677
(new Process(['git', 'commit', '-m', 'setup of original console files'], FLEX_TEST_DIR))->mustRun();
7778

78-
(new Process([__DIR__.'/../../vendor/bin/composer', 'install'], FLEX_TEST_DIR))->mustRun();
79+
(new Process([__DIR__.'/../../vendor/bin/composer', 'install', '--no-plugins'], FLEX_TEST_DIR))->mustRun();
7980

8081
$command = $this->createCommandUpdateRecipes();
81-
$command->execute(['package' => 'symfony/console']);
82+
$command->execute($input);
8283

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

92+
public function provideCommandInput()
93+
{
94+
return [
95+
[['package' => 'symfony/console']],
96+
[['--next' => true]],
97+
];
98+
}
99+
91100
private function createCommandUpdateRecipes(): CommandTester
92101
{
93102
$this->io = new BufferIO();

tests/Fixtures/update_recipes/composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
"license": "proprietary",
44
"require": {
55
"php": ">=7.1",
6-
"symfony/console": "5.4.*"
6+
"symfony/console": "5.4.*",
7+
"symfony/flex": "@dev"
78
},
89
"config": {
910
"allow-plugins": {
1011
"symfony/flex": true
1112
}
12-
}
13+
},
14+
"repositories": [
15+
{
16+
"type": "path",
17+
"url": ".."
18+
}
19+
]
1320
}

0 commit comments

Comments
 (0)