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

Show version in CLI #2291

Merged
merged 1 commit into from
Jun 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading