Skip to content

Commit

Permalink
Use InstalledVersions to get Drall version dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
jigarius committed Sep 23, 2024
1 parent 2fca390 commit c706a31
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/Drall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drall;

use Composer\InstalledVersions;
use Drall\Command\ExecCommand;
use Drall\Command\SiteAliasesCommand;
use Drall\Command\SiteDirectoriesCommand;
Expand All @@ -19,8 +20,6 @@ final class Drall extends Application {

const NAME = 'Drall';

const VERSION = '3.1.0-rc1';

use SiteDetectorAwareTrait;

/**
Expand All @@ -29,7 +28,7 @@ final class Drall extends Application {
public function __construct() {
parent::__construct();
$this->setName(self::NAME);
$this->setVersion(self::VERSION);
$this->setVersion(InstalledVersions::getPrettyVersion('jigarius/drall') ?? 'unknown');
$this->setAutoExit(FALSE);

$this->add(new SiteDirectoriesCommand());
Expand Down
4 changes: 3 additions & 1 deletion test/Integration/DrallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drall\Test\Integration;

use Composer\InstalledVersions;
use Drall\Drall;
use Drall\IntegrationTestCase;

Expand All @@ -12,7 +13,8 @@ class DrallTest extends IntegrationTestCase {

public function testVersion() {
$output = shell_exec('drall --version');
$this->assertEquals(Drall::NAME . ' ' . Drall::VERSION . PHP_EOL, $output);
$version = InstalledVersions::getPrettyVersion('jigarius/drall');
$this->assertEquals(Drall::NAME . ' ' . $version . PHP_EOL, $output);
}

public function testWorkingDirectory() {
Expand Down
10 changes: 2 additions & 8 deletions test/Unit/DrallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ public function testName() {
public function testVersion() {
$app = new Drall();
$this->assertMatchesRegularExpression(
'/^\d+\.\d+.\d+(-(alpha|beta|rc)\d+)?$/',
$app->getVersion()
'/^\d+\.\d+.\d+(-(alpha|beta|rc)\d+)?$|^\d+\.x-dev/',
$app->getVersion(),
);

$json_path = $this->projectDir() . DIRECTORY_SEPARATOR . 'composer.json';
$json_data = json_decode(file_get_contents($json_path));

$this->assertNotEmpty($json_data->version);
$this->assertEquals($json_data->version, $app->getVersion());
}

public function testDefaultInputOptions() {
Expand Down

0 comments on commit c706a31

Please sign in to comment.