Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: Application - better display version when displaying gitSha #6237

Merged
merged 1 commit into from Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Console/Application.php
Expand Up @@ -119,20 +119,20 @@ public function doRun(InputInterface $input, OutputInterface $output): int
*/
public function getLongVersion(): string
{
$version = implode('', [
$commit = '@git-commit@';
$versionCommit = '';

if ('@'.'git-commit@' !== $commit) { /** @phpstan-ignore-line as `$commit` is replaced during phar building */
$versionCommit = substr($commit, 0, 7);
}

return implode('', [
parent::getLongVersion(),
$versionCommit ? sprintf(' <info>(%s)</info>', $versionCommit) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
self::VERSION_CODENAME ? sprintf(' <info>%s</info>', self::VERSION_CODENAME) : '', // @phpstan-ignore-line to avoid `Ternary operator condition is always true|false.`
' by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>.',
"\nPHP runtime: <info>".PHP_VERSION.'</info>',
]);

$commit = '@git-commit@';

if ('@'.'git-commit@' !== $commit) { // @phpstan-ignore-line as `$commit` is replaced during phar building
$version .= ' ('.substr($commit, 0, 7).')';
}

return $version;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/Smoke/PharTest.php
Expand Up @@ -55,8 +55,11 @@ public static function setUpBeforeClass(): void

public function testVersion(): void
{
/** @phpstan-ignore-next-line to avoid `Ternary operator condition is always true|false.` */
$shouldExpectCodename = Application::VERSION_CODENAME ? 1 : 0;

static::assertMatchesRegularExpression(
sprintf("/^.* %s(?: %s)? by .*\nPHP runtime: \\d\\.\\d+\\..*\$/", Application::VERSION, Application::VERSION_CODENAME),
sprintf("/^PHP CS Fixer (?<version>%s)(?<git_sha> \\([a-z0-9]+\\))?(?<codename> %s){%d}(?<by> by .*)\nPHP runtime: (?<php_version>\\d\\.\\d+\\..*)$/", Application::VERSION, Application::VERSION_CODENAME, $shouldExpectCodename),
self::executePharCommand('--version')->getOutput()
);
}
Expand Down