Skip to content

Commit 8c6348b

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

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ protected function tearDown(): void
5757
* that we can easily use to assert.
5858
*
5959
* @requires PHP >= 7.2
60+
*
61+
* @dataProvider provideCommandInput
6062
*/
61-
public function testCommandUpdatesRecipe()
63+
public function testCommandUpdatesRecipe(array $input)
6264
{
6365
@mkdir(FLEX_TEST_DIR);
6466
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
@@ -75,10 +77,10 @@ public function testCommandUpdatesRecipe()
7577
(new Process(['git', 'add', '-A'], FLEX_TEST_DIR))->mustRun();
7678
(new Process(['git', 'commit', '-m', 'setup of original console files'], FLEX_TEST_DIR))->mustRun();
7779

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

8082
$command = $this->createCommandUpdateRecipes();
81-
$command->execute(['package' => 'symfony/console']);
83+
$command->execute($input);
8284

8385
$this->assertSame(0, $command->getStatusCode());
8486
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
@@ -88,6 +90,14 @@ public function testCommandUpdatesRecipe()
8890
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
8991
}
9092

93+
public function provideCommandInput()
94+
{
95+
return [
96+
[['package' => 'symfony/console']],
97+
[['--next' => true]],
98+
];
99+
}
100+
91101
private function createCommandUpdateRecipes(): CommandTester
92102
{
93103
$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)