Skip to content

Commit

Permalink
Improve output of --check-version CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 31, 2024
1 parent 6d70c68 commit 6b0162e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6b0162e

Please sign in to comment.