Skip to content

Commit

Permalink
minor #6237 DX: Application - better display version when displaying …
Browse files Browse the repository at this point in the history
…gitSha (keradus)

This PR was squashed before being merged into the master branch (closes #6237).

Discussion
----------

DX: Application - better display version when displaying gitSha

before the change of this PR, but after #6222 :
```
ker@dus:~/github/PHP-CS-Fixer λ ./php-cs-fixer.phar
PHP CS Fixer 3.5.0 The Creation by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.13 (333f15e)
```
it's misleading, as 333f15e is gitSha of Fixer, not of PHP runtime

Commits
-------

1b54c3e DX: Application - better display version when displaying gitSha
  • Loading branch information
SpacePossum committed Jan 18, 2022
2 parents 333f15e + 1b54c3e commit 3b3a5f0
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 3b3a5f0

Please sign in to comment.