From 5fa456ba7064cc32886ecb731653aeb4d5dd50e5 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:03:04 +0700 Subject: [PATCH 1/5] Add `gt` command --- app/Commander.php | 4 +- app/Commands/GreaterThanCommand.php | 75 +++++++++++++++++++ app/Commands/IncrementCommand.php | 5 +- app/Commands/ValidateCommand.php | 2 +- tests/app/Commands/GreaterThanCommandTest.php | 44 +++++++++++ 5 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 app/Commands/GreaterThanCommand.php create mode 100644 tests/app/Commands/GreaterThanCommandTest.php diff --git a/app/Commander.php b/app/Commander.php index a27b5f1..9ef0cbf 100644 --- a/app/Commander.php +++ b/app/Commander.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Syntatis\Version\CLI\Commands\GreaterThanCommand; use Syntatis\Version\CLI\Commands\IncrementCommand; use Syntatis\Version\CLI\Commands\ValidateCommand; @@ -15,7 +16,7 @@ final class Commander extends Application public function __construct() { - parent::__construct('Ver', self::VERSION); + parent::__construct('Version', self::VERSION); $this->addCommands($this->getCommands()); } @@ -29,6 +30,7 @@ private function getCommands(): array return [ new IncrementCommand(), new ValidateCommand(), + new GreaterThanCommand(), ]; } } diff --git a/app/Commands/GreaterThanCommand.php b/app/Commands/GreaterThanCommand.php new file mode 100644 index 0000000..70a6280 --- /dev/null +++ b/app/Commands/GreaterThanCommand.php @@ -0,0 +1,75 @@ +setName('gt'); + $this->setDescription('Compare if a version is greater than another'); + $this->addArgument('version-a', InputArgument::REQUIRED, 'First version to compare'); + $this->addArgument('version-b', InputArgument::REQUIRED, 'Second version to compare against the first'); + $this->setHelp(<<<'HELP' + This command compares two versions and checks if the first version is greater than the second. + + Usage: + version gt 1.0.0 0.9.0 + version gt 2.1.0 2.1.0 + HELP); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $style = new SymfonyStyle($input, $output); + $versionA = $input->getArgument('version-a'); + $versionB = $input->getArgument('version-b'); + + try { + if (! is_string($versionA)) { + throw new InvalidArgumentType($versionA); + } + + if (! is_string($versionB)) { + throw new InvalidArgumentType($versionB); + } + + /** @var Version $a */ + $a = Version::fromString($versionA); + + /** @var Version $b */ + $b = Version::fromString($versionB); + + if ($a->isGreaterThan($b)) { + $style->success(sprintf("Version '%s' is greater than '%s'.", $a, $b)); + + return Command::SUCCESS; + } + + $style->error(sprintf("Version '%s' is not greater than '%s'.", $a, $b)); + + return Command::FAILURE; + } catch (Throwable $th) { + $style->error($th->getMessage()); + + return Command::FAILURE; + } + } +} diff --git a/app/Commands/IncrementCommand.php b/app/Commands/IncrementCommand.php index e79e7cf..bdd39db 100644 --- a/app/Commands/IncrementCommand.php +++ b/app/Commands/IncrementCommand.php @@ -25,9 +25,8 @@ final class IncrementCommand extends Command protected function configure(): void { $this->setName('increment'); - $this->setDescription('Increment a version.'); - $this->setHelp('This command increments the provided version by the specified part (major, minor, patch).'); - $this->setAliases(['incr', 'bump']); + $this->setDescription('Increment a version'); + $this->setAliases(['incr']); $this->addArgument('version', InputArgument::REQUIRED, 'Version to increment'); $this->addOption('part', 'p', InputArgument::OPTIONAL, 'Part to increment (major, minor, patch)', 'patch'); $this->addOption('build', 'b', InputArgument::OPTIONAL, 'Build metadata to append to the version'); diff --git a/app/Commands/ValidateCommand.php b/app/Commands/ValidateCommand.php index f76b65a..7d62b47 100644 --- a/app/Commands/ValidateCommand.php +++ b/app/Commands/ValidateCommand.php @@ -24,7 +24,7 @@ final class ValidateCommand extends Command protected function configure(): void { $this->setName('validate'); - $this->setDescription('Validate a version.'); + $this->setDescription('Validate a version'); $this->setHelp('This command checks if the provided value is a valid Semantic Version (SemVer) version format.'); $this->setAliases(['val']); $this->addArgument('version', InputArgument::REQUIRED, 'Version to validate'); diff --git a/tests/app/Commands/GreaterThanCommandTest.php b/tests/app/Commands/GreaterThanCommandTest.php new file mode 100644 index 0000000..d18bc63 --- /dev/null +++ b/tests/app/Commands/GreaterThanCommandTest.php @@ -0,0 +1,44 @@ +commander = new Commander(); + } + + /** @dataProvider dataComparison */ + public function testComparison(string $versionA, string $versionB, string $expect): void + { + $tester = new CommandTester($this->commander->get('gt')); + $tester->execute(['version-a' => $versionA, 'version-b' => $versionB]); + + self::assertStringContainsString( + $expect, + $tester->getDisplay(), + ); + } + + public static function dataComparison(): iterable + { + yield ['1.0.0', '2.0.0', sprintf("[ERROR] Version '%s' is not greater than '%s'.", '1.0.0', '2.0.0')]; + yield ['2.0.0', '1.0.0', sprintf("[OK] Version '%s' is greater than '%s'.", '2.0.0', '1.0.0')]; + yield ['1.0.0', '1.0.0', sprintf("[ERROR] Version '%s' is not greater than '%s'.", '1.0.0', '1.0.0')]; + yield ['1.0.0-alpha.1', '1.0.0-alpha.2', sprintf("[ERROR] Version '%s' is not greater than '%s'.", '1.0.0-alpha.1', '1.0.0-alpha.2')]; + yield ['1.0.0-alpha.2', '1.0.0-alpha.1', sprintf("[OK] Version '%s' is greater than '%s'.", '1.0.0-alpha.2', '1.0.0-alpha.1')]; + } +} From 2e91f191ee0889870e518aaa5e02f34c2cd4c3c9 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:06:24 +0700 Subject: [PATCH 2/5] Rename to `phpunit` --- phpunit.xml.dist | 4 ++-- tests/{app => phpunit}/Commands/GreaterThanCommandTest.php | 0 tests/{app => phpunit}/Commands/IncrementCommandTest.php | 0 tests/{app => phpunit}/Commands/ValidateCommandTest.php | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename tests/{app => phpunit}/Commands/GreaterThanCommandTest.php (100%) rename tests/{app => phpunit}/Commands/IncrementCommandTest.php (100%) rename tests/{app => phpunit}/Commands/ValidateCommandTest.php (100%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 01f6e31..ad87e4c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,8 +11,8 @@ printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer" > - - tests/app/ + + tests/phpunit/ diff --git a/tests/app/Commands/GreaterThanCommandTest.php b/tests/phpunit/Commands/GreaterThanCommandTest.php similarity index 100% rename from tests/app/Commands/GreaterThanCommandTest.php rename to tests/phpunit/Commands/GreaterThanCommandTest.php diff --git a/tests/app/Commands/IncrementCommandTest.php b/tests/phpunit/Commands/IncrementCommandTest.php similarity index 100% rename from tests/app/Commands/IncrementCommandTest.php rename to tests/phpunit/Commands/IncrementCommandTest.php diff --git a/tests/app/Commands/ValidateCommandTest.php b/tests/phpunit/Commands/ValidateCommandTest.php similarity index 100% rename from tests/app/Commands/ValidateCommandTest.php rename to tests/phpunit/Commands/ValidateCommandTest.php From 1989e7b5051c14c8ef0d6ddea5e9782eead61293 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:24:45 +0700 Subject: [PATCH 3/5] Update `matrix` --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29a8bd0..f3b59ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,6 +68,8 @@ jobs: max-parallel: 3 matrix: php: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + stability: [prefer-lowest, prefer-stable] + machine: [windows-latest, ubuntu-latest] steps: - name: Checkout code From fd78fdac896a70c48c030544cb6f182be4bb9d5f Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:25:47 +0700 Subject: [PATCH 4/5] Fix paths --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6fcd983..fa14e6c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ parameters: level: 10 paths: - app - - tests/app + - tests/phpunit ignoreErrors: - identifier: missingType.iterableValue From d994f8a809811f2ce5925a8a3d4f0f1fff56cfab Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Mon, 28 Jul 2025 12:32:53 +0700 Subject: [PATCH 5/5] Update with `non-feature-branches` --- composer.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ee16d62..ab86dda 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,11 @@ { "name": "syntatis/version-cli", "description": "Validate, increment, and compare SemVer-compliant version number with CLI", - "keywords": ["version", "cli", "semver"], + "keywords": [ + "version", + "cli", + "semver" + ], "authors": [ { "name": "Thoriq Firdaus" @@ -57,5 +61,8 @@ }, "preferred-install": "dist", "sort-packages": true - } + }, + "non-feature-branches": [ + "dependabot/*" + ] }