From 6b0162e69016b325a347ffd7868247d4e49eda1e Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 31 Jan 2024 11:21:26 +0100 Subject: [PATCH] Improve output of --check-version CLI option --- src/TextUI/Command.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 0f6e5284351..32f52f96342 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -1142,17 +1142,31 @@ protected function handleVersionCheck(): void { $this->printVersionString(); - $latestVersion = file_get_contents('https://phar.phpunit.de/latest-version-of/phpunit'); - $isOutdated = version_compare($latestVersion, Version::id(), '>'); + $latestVersion = file_get_contents('https://phar.phpunit.de/latest-version-of/phpunit'); + $latestCompatibleVersion = file_get_contents('https://phar.phpunit.de/latest-version-of/phpunit-' . explode('.', Version::series())[0]); - if ($isOutdated) { + $notLatest = version_compare($latestVersion, Version::id(), '>'); + $notLatestCompatible = version_compare($latestCompatibleVersion, Version::id(), '>'); + + if ($notLatest || $notLatestCompatible) { + print 'You are not using the latest version of PHPUnit.' . PHP_EOL; + } else { + print 'You are using the latest version of PHPUnit.' . PHP_EOL; + } + + if ($notLatestCompatible) { + printf( + 'The latest version compatible with PHPUnit %s is PHPUnit %s.' . PHP_EOL, + Version::id(), + $latestCompatibleVersion + ); + } + + if ($notLatest) { printf( - 'You are not using the latest version of PHPUnit.' . PHP_EOL . 'The latest version is PHPUnit %s.' . PHP_EOL, $latestVersion ); - } else { - print 'You are using the latest version of PHPUnit.' . PHP_EOL; } exit(TestRunner::SUCCESS_EXIT);