From ad702c973cf3e4e40983ac5fadfa8b6a32c743b0 Mon Sep 17 00:00:00 2001 From: TangRufus Date: Fri, 5 Jun 2026 04:53:01 +0100 Subject: [PATCH] Upgrade `symfony/console` to v8.1 --- composer.json | 2 +- composer.lock | 159 +++++++++++++----- ....php__is_not_a_valid_constraint_ruby.txtar | 4 +- .../fail/testdata/unsatisfiable_2.txtar | 2 +- .../composer/misc/testdata/bad_mode.txtar | 6 +- .../composer/misc/testdata/bad_source.txtar | 6 +- internal/constraint/fail/testdata/ruby.txtar | 2 +- .../fail/testdata/unsatisfiable_2.txtar | 2 +- .../constraint/misc/testdata/bad_mode.txtar | 6 +- .../constraint/misc/testdata/bad_source.txtar | 6 +- src/Console/ComposerCommand.php | 9 +- src/Console/ConstraintCommand.php | 14 +- src/Console/FromNameTrait.php | 27 --- src/Console/Mode.php | 28 +-- src/Console/ModeOption.php | 22 --- src/Console/Runner.php | 2 + src/Console/Source.php | 30 +--- src/Console/SourceOption.php | 22 --- tests/Unit/Console/CommandHelpTest.php | 30 ++++ 19 files changed, 193 insertions(+), 186 deletions(-) delete mode 100644 src/Console/FromNameTrait.php delete mode 100644 src/Console/ModeOption.php delete mode 100644 src/Console/SourceOption.php create mode 100644 tests/Unit/Console/CommandHelpTest.php diff --git a/composer.json b/composer.json index f0193b6..274b050 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "composer-runtime-api": "^2.2", "composer/semver": "^3.4", "guzzlehttp/guzzle": "^7.10", - "symfony/console": "^7.3", + "symfony/console": "^8.1", "symfony/polyfill-iconv": "^1.33" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 55a7aa9..0ccde01 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5f930bed48e2837f57f9883022e398bc", + "content-hash": "59f35d924fdd412b9f3ab7deb9ee059f", "packages": [ { "name": "composer/semver", @@ -85,25 +85,26 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.10.6", + "version": "7.11.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "e7412b3180912c01650cc66647f18c1d1cbe9b94" + "reference": "c987f8ce84b8434fa430795eca0f3430663da72b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e7412b3180912c01650cc66647f18c1d1cbe9b94", - "reference": "e7412b3180912c01650cc66647f18c1d1cbe9b94", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/c987f8ce84b8434fa430795eca0f3430663da72b", + "reference": "c987f8ce84b8434fa430795eca0f3430663da72b", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^2.3", - "guzzlehttp/psr7": "^2.8", + "guzzlehttp/promises": "^2.5", + "guzzlehttp/psr7": "^2.11", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" + "symfony/deprecation-contracts": "^2.5 || ^3.0", + "symfony/polyfill-php80": "^1.24" }, "provide": { "psr/http-client-implementation": "1.0" @@ -192,7 +193,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.10.6" + "source": "https://github.com/guzzle/guzzle/tree/7.11.0" }, "funding": [ { @@ -208,7 +209,7 @@ "type": "tidelift" } ], - "time": "2026-06-01T13:06:22+00:00" + "time": "2026-06-02T12:40:51+00:00" }, { "name": "guzzlehttp/promises", @@ -672,47 +673,49 @@ }, { "name": "symfony/console", - "version": "v7.4.13", + "version": "v8.1.0", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "85095d2573eaefaf35e40b9513a9bf09f72cd217" + "reference": "f5a856c6ecb56b3c21ed94a5b7bf940d857d110a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/85095d2573eaefaf35e40b9513a9bf09f72cd217", - "reference": "85095d2573eaefaf35e40b9513a9bf09f72cd217", + "url": "https://api.github.com/repos/symfony/console/zipball/f5a856c6ecb56b3c21ed94a5b7bf940d857d110a", + "reference": "f5a856c6ecb56b3c21ed94a5b7bf940d857d110a", "shasum": "" }, "require": { - "php": ">=8.2", + "php": ">=8.4.1", "symfony/deprecation-contracts": "^2.5|^3", - "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-mbstring": "^1.0", + "symfony/polyfill-php85": "^1.32", "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^7.2|^8.0" + "symfony/string": "^7.4.6|^8.0.6" }, "conflict": { - "symfony/dependency-injection": "<6.4", - "symfony/dotenv": "<6.4", - "symfony/event-dispatcher": "<6.4", - "symfony/lock": "<6.4", - "symfony/process": "<6.4" + "symfony/dependency-injection": "<8.1", + "symfony/event-dispatcher": "<8.1" }, "provide": { "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0|^8.0", - "symfony/dependency-injection": "^6.4|^7.0|^8.0", - "symfony/event-dispatcher": "^6.4|^7.0|^8.0", - "symfony/http-foundation": "^6.4|^7.0|^8.0", - "symfony/http-kernel": "^6.4|^7.0|^8.0", - "symfony/lock": "^6.4|^7.0|^8.0", - "symfony/messenger": "^6.4|^7.0|^8.0", - "symfony/process": "^6.4|^7.0|^8.0", - "symfony/stopwatch": "^6.4|^7.0|^8.0", - "symfony/var-dumper": "^6.4|^7.0|^8.0" + "symfony/config": "^7.4|^8.0", + "symfony/dependency-injection": "^8.1", + "symfony/event-dispatcher": "^8.1", + "symfony/filesystem": "^7.4|^8.0", + "symfony/http-foundation": "^7.4|^8.0", + "symfony/http-kernel": "^7.4|^8.0", + "symfony/lock": "^7.4|^8.0", + "symfony/messenger": "^7.4|^8.0", + "symfony/mime": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0", + "symfony/stopwatch": "^7.4|^8.0", + "symfony/uid": "^7.4|^8.0", + "symfony/validator": "^7.4|^8.0", + "symfony/var-dumper": "^7.4|^8.0" }, "type": "library", "autoload": { @@ -746,7 +749,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.4.13" + "source": "https://github.com/symfony/console/tree/v8.1.0" }, "funding": [ { @@ -766,7 +769,7 @@ "type": "tidelift" } ], - "time": "2026-05-24T08:56:14+00:00" + "time": "2026-05-29T05:06:50+00:00" }, { "name": "symfony/deprecation-contracts", @@ -1342,6 +1345,86 @@ ], "time": "2026-04-10T16:19:22+00:00" }, + { + "name": "symfony/polyfill-php85", + "version": "v1.38.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php85.git", + "reference": "ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php85/zipball/ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1", + "reference": "ba2ba04f3352cfa2dcbbcb90aee13ed967f505b1", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php85\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.5+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php85/tree/v1.38.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2026-05-26T02:25:22+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.7.0", @@ -3363,11 +3446,11 @@ }, { "name": "phpstan/phpstan", - "version": "2.2.1", + "version": "2.2.2", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dea9c8f2d25cc849391042b71e429c1a4bf82660", - "reference": "dea9c8f2d25cc849391042b71e429c1a4bf82660", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e5cc34d491a90e79c216d824f60fe21fd4d93bd6", + "reference": "e5cc34d491a90e79c216d824f60fe21fd4d93bd6", "shasum": "" }, "require": { @@ -3423,7 +3506,7 @@ "type": "github" } ], - "time": "2026-05-28T14:44:12+00:00" + "time": "2026-06-05T09:00:01+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", diff --git a/internal/composer/fail/testdata/_require.php__is_not_a_valid_constraint_ruby.txtar b/internal/composer/fail/testdata/_require.php__is_not_a_valid_constraint_ruby.txtar index 4f30f5d..24371b5 100644 --- a/internal/composer/fail/testdata/_require.php__is_not_a_valid_constraint_ruby.txtar +++ b/internal/composer/fail/testdata/_require.php__is_not_a_valid_constraint_ruby.txtar @@ -20,8 +20,8 @@ cmp stderr stderr.golden -- stderr.golden -- - [ERROR] The "require.php" field is not a valid version constraint: Could not parse version constraint ~>1.0: Invalid - operator "~>", you probably meant to use the "~" operator + [ERROR] The "require.php" field is not a valid version constraint: Could not parse version constraint ~>1.0: Invalid + operator "~>", you probably meant to use the "~" operator -- composer.json -- {"require":{"php":"~>1.0"}} diff --git a/internal/composer/fail/testdata/unsatisfiable_2.txtar b/internal/composer/fail/testdata/unsatisfiable_2.txtar index 9193028..818f63c 100644 --- a/internal/composer/fail/testdata/unsatisfiable_2.txtar +++ b/internal/composer/fail/testdata/unsatisfiable_2.txtar @@ -20,7 +20,7 @@ cmp stderr stderr.golden -- stderr.golden -- - [ERROR] No PHP versions could satisfy the constraint ">999". + [ERROR] No PHP versions could satisfy the constraint ">999". -- composer.json -- {"require":{"php":">999"}} diff --git a/internal/composer/misc/testdata/bad_mode.txtar b/internal/composer/misc/testdata/bad_mode.txtar index aad6dbf..5d4b5a4 100644 --- a/internal/composer/misc/testdata/bad_mode.txtar +++ b/internal/composer/misc/testdata/bad_mode.txtar @@ -4,9 +4,9 @@ cmp stderr stderr.golden -- stderr.golden -- - - [ERROR] Invalid --mode "bad". Available modes: [full, minor-only] - + + The value "bad" is not valid for the "mode" option. Supported values are "full", "minor-only". + composer [--source SOURCE] [--mode MODE] [--] [] diff --git a/internal/composer/misc/testdata/bad_source.txtar b/internal/composer/misc/testdata/bad_source.txtar index 6329021..41b56b0 100644 --- a/internal/composer/misc/testdata/bad_source.txtar +++ b/internal/composer/misc/testdata/bad_source.txtar @@ -4,9 +4,9 @@ cmp stderr stderr.golden -- stderr.golden -- - - [ERROR] Invalid --source "bad". Available sources: [auto, php.net, offline] - + + The value "bad" is not valid for the "source" option. Supported values are "auto", "php.net", "offline". + composer [--source SOURCE] [--mode MODE] [--] [] diff --git a/internal/constraint/fail/testdata/ruby.txtar b/internal/constraint/fail/testdata/ruby.txtar index 0e17414..a8d948c 100644 --- a/internal/constraint/fail/testdata/ruby.txtar +++ b/internal/constraint/fail/testdata/ruby.txtar @@ -20,5 +20,5 @@ cmp stderr stderr.golden -- stderr.golden -- - [ERROR] Could not parse version constraint ~>1.0: Invalid operator "~>", you probably meant to use the "~" operator + [ERROR] Could not parse version constraint ~>1.0: Invalid operator "~>", you probably meant to use the "~" operator diff --git a/internal/constraint/fail/testdata/unsatisfiable_2.txtar b/internal/constraint/fail/testdata/unsatisfiable_2.txtar index 79cbf9b..0d699e0 100644 --- a/internal/constraint/fail/testdata/unsatisfiable_2.txtar +++ b/internal/constraint/fail/testdata/unsatisfiable_2.txtar @@ -20,5 +20,5 @@ cmp stderr stderr.golden -- stderr.golden -- - [ERROR] No PHP versions could satisfy the constraint ">999". + [ERROR] No PHP versions could satisfy the constraint ">999". diff --git a/internal/constraint/misc/testdata/bad_mode.txtar b/internal/constraint/misc/testdata/bad_mode.txtar index 8ee5b0a..64fb772 100644 --- a/internal/constraint/misc/testdata/bad_mode.txtar +++ b/internal/constraint/misc/testdata/bad_mode.txtar @@ -4,9 +4,9 @@ cmp stderr stderr.golden -- stderr.golden -- - - [ERROR] Invalid --mode "bad". Available modes: [full, minor-only] - + + The value "bad" is not valid for the "mode" option. Supported values are "full", "minor-only". + constraint [--source SOURCE] [--mode MODE] [--] diff --git a/internal/constraint/misc/testdata/bad_source.txtar b/internal/constraint/misc/testdata/bad_source.txtar index 0f59ca6..52dc880 100644 --- a/internal/constraint/misc/testdata/bad_source.txtar +++ b/internal/constraint/misc/testdata/bad_source.txtar @@ -4,9 +4,9 @@ cmp stderr stderr.golden -- stderr.golden -- - - [ERROR] Invalid --source "bad". Available sources: [auto, php.net, offline] - + + The value "bad" is not valid for the "source" option. Supported values are "auto", "php.net", "offline". + constraint [--source SOURCE] [--mode MODE] [--] diff --git a/src/Console/ComposerCommand.php b/src/Console/ComposerCommand.php index aeae05d..fa9c6e4 100644 --- a/src/Console/ComposerCommand.php +++ b/src/Console/ComposerCommand.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; use TypistTech\PhpMatrix\Composer; @@ -25,10 +26,10 @@ public function __invoke( Application $application, #[Argument(description: 'Path to composer.json file.')] string $path = './composer.json', - #[SourceOption] - string $source = Source::Auto->value, - #[ModeOption] - string $mode = Mode::MinorOnly->value, + #[Option(description: Source::DESCRIPTION)] + Source $source = Source::Auto, + #[Option(description: Mode::DESCRIPTION)] + Mode $mode = Mode::MinorOnly, ): int { try { $composer = Composer::fromFile($path); diff --git a/src/Console/ConstraintCommand.php b/src/Console/ConstraintCommand.php index 8f7e635..d6a2d17 100644 --- a/src/Console/ConstraintCommand.php +++ b/src/Console/ConstraintCommand.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Style\SymfonyStyle; use TypistTech\PhpMatrix\Exceptions\ExceptionInterface; @@ -30,16 +31,13 @@ public function __invoke( SymfonyStyle $io, #[Argument(description: 'The version constraint.')] string $constraint, - #[SourceOption] - string $source = Source::Auto->value, - #[ModeOption] - string $mode = Mode::MinorOnly->value, + #[Option(description: Source::DESCRIPTION)] + Source $source = Source::Auto, + #[Option(description: Mode::DESCRIPTION)] + Mode $mode = Mode::MinorOnly, ): int { try { - $matrix = $this->matrixFactory->make( - Source::fromValue($source), - Mode::fromValue($mode), - ); + $matrix = $this->matrixFactory->make($source, $mode); $versions = $matrix->satisfiedBy($constraint); if ($versions === []) { diff --git a/src/Console/FromNameTrait.php b/src/Console/FromNameTrait.php deleted file mode 100644 index 5704808..0000000 --- a/src/Console/FromNameTrait.php +++ /dev/null @@ -1,27 +0,0 @@ -full: Report all satisfying versions in MAJOR.MINOR.PATCH format + - minor-only: Report MAJOR.MINOR versions only - public const string NAME = 'mode'; + DESCRIPTION; public function matrix(ReleasesInterface $releases): MatrixInterface { @@ -25,25 +28,4 @@ public function matrix(ReleasesInterface $releases): MatrixInterface self::MinorOnly => new MinorOnlyMatrix($releases), }; } - - public static function description(): string - { - $desc = 'Available modes:'.PHP_EOL; - - foreach (self::cases() as $mode) { - $desc .= "- {$mode->value}: {$mode->explanation()}".PHP_EOL; - } - - $desc .= PHP_EOL; - - return $desc; - } - - private function explanation(): string - { - return match ($this) { - self::Full => 'Report all satisfying versions in MAJOR.MINOR.PATCH format', - self::MinorOnly => 'Report MAJOR.MINOR versions only', - }; - } } diff --git a/src/Console/ModeOption.php b/src/Console/ModeOption.php deleted file mode 100644 index 4e61c4d..0000000 --- a/src/Console/ModeOption.php +++ /dev/null @@ -1,22 +0,0 @@ -auto: Use offline in minor-only mode. Otherwise, fetch from php.net + - php.net: Fetch releases information from php.net + - offline: Use hardcoded releases information - public const string NAME = 'source'; + DESCRIPTION; public function releases(Mode $mode): ReleasesInterface { @@ -32,26 +36,4 @@ public function releases(Mode $mode): ReleasesInterface self::Offline => new OfflineReleases, }; } - - public static function description(): string - { - $desc = 'Available sources:'.PHP_EOL; - - foreach (self::cases() as $source) { - $desc .= "- {$source->value}: {$source->explanation()}".PHP_EOL; - } - - $desc .= PHP_EOL; - - return $desc; - } - - private function explanation(): string - { - return match ($this) { - self::Auto => 'Use offline in minor-only mode. Otherwise, fetch from php.net', - self::PhpNet => 'Fetch releases information from php.net', - self::Offline => 'Use hardcoded releases information', - }; - } } diff --git a/src/Console/SourceOption.php b/src/Console/SourceOption.php deleted file mode 100644 index e553c8c..0000000 --- a/src/Console/SourceOption.php +++ /dev/null @@ -1,22 +0,0 @@ -addCommands([ + new ComposerCommand, + new ConstraintCommand, + ]); + + $definition = $application->get($commandName)->getDefinition(); + + expect($definition->getOption('source')->getDescription())->toBe(Source::DESCRIPTION) + ->and($definition->getOption('mode')->getDescription())->toBe(Mode::DESCRIPTION); +})->with([ + 'composer', + 'constraint', +]);