Skip to content

Commit

Permalink
minor #6222 Show runtime on version command (SpacePossum)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the master branch (closes #6222).

Discussion
----------

Show runtime on version command

Show the PHP runtime on version command (php-cs-fixer -V), simplify code.

Commits
-------

85bf144 Show runtime on version command
  • Loading branch information
SpacePossum committed Jan 12, 2022
2 parents ee92352 + 85bf144 commit 6fe4c69
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 12 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -10,8 +10,7 @@ labels: kind/bug
Before reporting a bug, make sure PHP CS Fixer is up-to-date.
Please describe the problem and provide technical details such as:
* PHP version: php -v
* PHP CS Fixer version: php-cs-fixer -V
* PHP CS Fixer version and PHP runtime: php-cs-fixer -V
* the command used to run PHP CS Fixer (run with `-vvv`)
* the configuration (file) you used
-->
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Application.php
Expand Up @@ -122,7 +122,8 @@ public function getLongVersion(): string
$version = implode('', [
parent::getLongVersion(),
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>',
' by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>.',
"\nPHP runtime: <info>".PHP_VERSION.'</info>',
]);

$commit = '@git-commit@';
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/DescribeCommand.php
Expand Up @@ -101,7 +101,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() && $output instanceof ConsoleOutputInterface) {
$stdErr = $output->getErrorOutput();
$stdErr->writeln($this->getApplication()->getLongVersion());
$stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
}

$name = $input->getArgument('name');
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/FixCommand.php
Expand Up @@ -268,7 +268,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (null !== $stdErr) {
if (OutputInterface::VERBOSITY_VERBOSE <= $verbosity) {
$stdErr->writeln($this->getApplication()->getLongVersion());
$stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
}

$configFile = $resolver->getConfigFile();
Expand Down
1 change: 0 additions & 1 deletion src/Console/Command/SelfUpdateCommand.php
Expand Up @@ -100,7 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() && $output instanceof ConsoleOutputInterface) {
$stdErr = $output->getErrorOutput();
$stdErr->writeln($this->getApplication()->getLongVersion());
$stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
}

if (!$this->toolInfo->isInstalledAsPhar()) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/ApplicationTest.php
Expand Up @@ -27,7 +27,7 @@ final class ApplicationTest extends TestCase
public function testApplication(): void
{
$app = new Application();
static::assertStringMatchesFormat('%s by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>', $app->getLongVersion());
static::assertStringMatchesFormat("%s by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>.\nPHP runtime: <info>%d.%d.%d</info>", $app->getLongVersion());
}

public function testGetMajorVersion(): void
Expand Down
7 changes: 3 additions & 4 deletions tests/Smoke/CiIntegrationTest.php
Expand Up @@ -166,17 +166,16 @@ public function testIntegration(

/** @phpstan-ignore-next-line to avoid `Ternary operator condition is always true|false.` */
$aboutSubpattern = Application::VERSION_CODENAME
? 'PHP CS Fixer '.preg_quote(Application::VERSION, '/').' '.preg_quote(Application::VERSION_CODENAME, '/').' by Fabien Potencier and Dariusz Ruminski'
: 'PHP CS Fixer '.preg_quote(Application::VERSION, '/').' by Fabien Potencier and Dariusz Ruminski';
? 'PHP CS Fixer '.preg_quote(Application::VERSION, '/').' '.preg_quote(Application::VERSION_CODENAME, '/')." by Fabien Potencier and Dariusz Ruminski.\nPHP runtime: ".PHP_VERSION
: 'PHP CS Fixer '.preg_quote(Application::VERSION, '/')." by Fabien Potencier and Dariusz Ruminski.\nPHP runtime: ".PHP_VERSION;

$pattern = sprintf(
'/^(?:%s)?(?:%s)?(?:%s)?(?:%s)?%s\n%s\n%s\n([\.S]{%d})%s\n%s$/',
'/^(?:%s)?(?:%s)?(?:%s)?(?:%s)?%s\n%s\n([\.S]{%d})%s\n%s$/',
preg_quote($optionalDeprecatedVersionWarning, '/'),
preg_quote($optionalIncompatibilityWarning, '/'),
preg_quote($optionalXdebugWarning, '/'),
preg_quote($optionalWarningsHelp, '/'),
$aboutSubpattern,
preg_quote(sprintf('Runtime: PHP %s', PHP_VERSION), '/'),
preg_quote('Loaded config default from ".php-cs-fixer.dist.php".', '/'),
\strlen($expectedResult3FilesDots),
preg_quote($expectedResult3FilesPercentage, '/'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke/PharTest.php
Expand Up @@ -56,7 +56,7 @@ public static function setUpBeforeClass(): void
public function testVersion(): void
{
static::assertMatchesRegularExpression(
'/^.* '.Application::VERSION.'(?: '.Application::VERSION_CODENAME.')? by .*$/',
sprintf("/^.* %s(?: %s)? by .*\nPHP runtime: \\d\\.\\d+\\..*\$/", Application::VERSION, Application::VERSION_CODENAME),
self::executePharCommand('--version')->getOutput()
);
}
Expand Down

0 comments on commit 6fe4c69

Please sign in to comment.