Skip to content

Commit

Permalink
Show version in CLI (#2291)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Jun 14, 2024
1 parent 5830da2 commit 6154850
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
5 changes: 3 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"KevinGH\\Box\\Compactor\\Php"
],
"directories": ["src", "app", "data", "vendor/symfony/console/Resources"],
"exclude-composer-files": false,
"files": [
"LICENSE"
],
Expand All @@ -24,6 +25,6 @@
"in": "vendor"
}
],
"output": "phinx.phar",
"exclude-composer-files": false
"git-tag": "git_tag",
"output": "phinx.phar"
}
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@
],
"require": {
"php-64bit": ">=8.1",
"composer-runtime-api": "^2.0",
"cakephp/database": "^5.0.2",
"psr/container": "^1.1|^2.0",
"symfony/console": "^6.0|^7.0",
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0"
"symfony/config": "^3.4|^4.0|^5.0|^6.0|^7.0",
"symfony/console": "^6.0|^7.0"
},
"require-dev": {
"ext-json": "*",
"ext-pdo": "*",
"phpunit/phpunit": "^9.5.19",
"cakephp/cakephp": "^5.0.2",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^9.5.19",
"symfony/yaml": "^3.4|^4.0|^5.0|^6.0|^7.0"
},
"autoload": {
Expand Down
30 changes: 29 additions & 1 deletion src/Phinx/Console/PhinxApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Phinx\Console;

use Composer\InstalledVersions;
use Phinx\Console\Command\Breakpoint;
use Phinx\Console\Command\Create;
use Phinx\Console\Command\Init;
Expand All @@ -27,12 +28,17 @@
*/
class PhinxApplication extends Application
{
/**
* @var string The current application version as determined by the getVersion() function.
*/
private string $version;

/**
* Initialize the Phinx console application.
*/
public function __construct()
{
parent::__construct('Phinx by CakePHP - https://phinx.org.');
parent::__construct('Phinx by CakePHP - https://phinx.org.', $this->getVersion());

$this->addCommands([
new Init(),
Expand Down Expand Up @@ -68,4 +74,26 @@ public function doRun(InputInterface $input, OutputInterface $output): int

return parent::doRun($input, $output);
}

/**
* Get the current application version.
*
* @return string The application version if it could be found, otherwise 'UNKNOWN'
*/
public function getVersion(): string
{
if (isset($this->version)) {
return $this->version;
}

// humbug/box will replace this with actual version when building
// so use that if available
$gitTag = '@git_tag@';
if (!str_starts_with($gitTag, '@')) {
return $this->version = $gitTag;
}

// Otherwise fallback to the version as reported by composer
return $this->version = InstalledVersions::getPrettyVersion('robmorgan/phinx') ?? 'UNKNOWN';
}
}
5 changes: 4 additions & 1 deletion tests/Phinx/Console/PhinxApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public function testRun($command, $result)
$stream = $appTester->getOutput()->getStream();
rewind($stream);

$this->assertStringContainsString($result, stream_get_contents($stream));
$contents = stream_get_contents($stream);

$this->assertMatchesRegularExpression('/^Phinx by CakePHP - https:\/\/phinx.org\. .+\n/', $contents);
$this->assertStringContainsString($result, $contents);
}

public function provider()
Expand Down

0 comments on commit 6154850

Please sign in to comment.