Skip to content

Commit

Permalink
DX: Application - better display version when displaying gitSha
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus authored and SpacePossum committed Jan 18, 2022
1 parent 333f15e commit 1b54c3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
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

0 comments on commit 1b54c3e

Please sign in to comment.