Skip to content
Open
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
4 changes: 3 additions & 1 deletion 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(): void
->setAliases(['recipes:update'])
->setDescription('Updates an already-installed recipe to the latest version.')
->addArgument('package', InputArgument::OPTIONAL, 'Recipe that should be updated.')
->addOption('no-changelog', null, InputOption::VALUE_NONE, 'Do not generate the changelog after updating the recipe.')
;
}

Expand Down Expand Up @@ -247,7 +249,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

if ($patch->getPatch()) {
if ($patch->getPatch() && !$input->getOption('no-changelog')) {
$io->write('');
$io->write(' Calculating CHANGELOG...', false);
$changelog = $this->generateChangelog($originalRecipe);
Expand Down
50 changes: 39 additions & 11 deletions tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,45 @@ protected function tearDown(): void
*
* @requires PHP >= 7.2
*/
public function testCommandUpdatesRecipe()
public function testCommandUpdatesRecipe(): void
{
$this->prepareRecipeUpdateFixture();

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

$this->assertSame(0, $command->getStatusCode());
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
// assert bin/console has changed
$this->assertStringNotContainsString('vendor/autoload.php', file_get_contents(FLEX_TEST_DIR.'/bin/console'));
// assert the recipe was updated
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
}

/**
* @requires PHP >= 7.2
*/
public function testCommandUpdatesRecipeWithNoChangelog(): void
{
$this->prepareRecipeUpdateFixture();

$command = $this->createCommandUpdateRecipes();
$command->execute([
'package' => 'symfony/console',
'--no-changelog' => true,
]);

$this->assertSame(0, $command->getStatusCode());
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
$this->assertStringNotContainsString('Calculating CHANGELOG', $this->io->getOutput());
$this->assertStringNotContainsString('No CHANGELOG could be calculated.', $this->io->getOutput());
// assert bin/console has changed
$this->assertStringNotContainsString('vendor/autoload.php', file_get_contents(FLEX_TEST_DIR.'/bin/console'));
// assert the recipe was updated
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
}

private function prepareRecipeUpdateFixture(): void
{
@mkdir(FLEX_TEST_DIR);
(new Process(['git', 'init'], FLEX_TEST_DIR))->mustRun();
Expand All @@ -76,16 +114,6 @@ public function testCommandUpdatesRecipe()
(new Process(['git', 'commit', '-m', 'setup of original console files'], FLEX_TEST_DIR))->mustRun();

(new Process([__DIR__.'/../../vendor/bin/composer', 'install'], FLEX_TEST_DIR))->mustRun();

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

$this->assertSame(0, $command->getStatusCode());
$this->assertStringContainsString('Recipe updated', $this->io->getOutput());
// assert bin/console has changed
$this->assertStringNotContainsString('vendor/autoload.php', file_get_contents(FLEX_TEST_DIR.'/bin/console'));
// assert the recipe was updated
$this->assertStringNotContainsString('c6d02bdfba9da13c22157520e32a602dbee8a75c', file_get_contents(FLEX_TEST_DIR.'/symfony.lock'));
}

private function createCommandUpdateRecipes(): CommandTester
Expand Down
Loading