From 3f2c3c5d693c6b869a6a5b86db17fb1279b7bfdd Mon Sep 17 00:00:00 2001 From: Eugene Leonovich Date: Thu, 28 Apr 2022 02:36:25 +0200 Subject: [PATCH] Fix TarantoolVersionRequirement to support the new versioning scheme See https://github.com/tarantool/tarantool/discussions/6182. See https://github.com/tarantool-php/client/issues/79. --- .../Requirement/TarantoolVersionRequirement.php | 9 +++++++-- .../Requirement/TarantoolVersionRequirementTest.php | 11 ++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Annotation/Requirement/TarantoolVersionRequirement.php b/src/Annotation/Requirement/TarantoolVersionRequirement.php index 792b8f9..7d8ecb4 100644 --- a/src/Annotation/Requirement/TarantoolVersionRequirement.php +++ b/src/Annotation/Requirement/TarantoolVersionRequirement.php @@ -36,7 +36,7 @@ public function getName() : string public function check(string $value) : ?string { - // replace dash with dot + // Replace dash with dot. $constraints = preg_replace('/(\d+\.\d+\.\d+)-(\d+)/', '$1.$2', $value); if (Semver::satisfies($this->getVersion(), $constraints)) { @@ -53,9 +53,14 @@ private function getVersion() : string } $version = $this->client->call('box.info')[0]['version']; - // normalize 2.2.1-3-g878e2a42c to 2.2.1.3 + + // Normalize 2.2.1-3-g878e2a42c to 2.2.1.3. $version = preg_replace('/-(\d+)-[^-]+$/', '.$1', $version); + // Treat "entrypoint" versions as "dev", + // so 2.11.0-entrypoint.8 becomes 2.11.0-dev+entrypoint.8. + $version = preg_replace('/(\d)-entrypoint/', '$1-dev+entrypoint', $version); + return $this->version = $version; } } diff --git a/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php b/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php index ada5e9b..57983dc 100755 --- a/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php +++ b/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php @@ -83,6 +83,15 @@ public function provideCheckPassesForValidConstraintsData() : iterable [$v2_3_1_3, '< 2.3.2'], [$v2_3_1_3, '< 2.4'], [$v2_3_1_3, '< 3'], + + // @see https://github.com/tarantool/tarantool/discussions/6182 + ['2.11.0-entrypoint', '< 2.11.0-alpha'], + ['2.11.0-entrypoint.8', '< 2.11.0-alpha'], + ['2.11.0-entrypoint.8', '< 2.11.1'], + ['2.11.0-entrypoint', '= 2.11.0-dev'], + ['2.11.0-entrypoint.8', '= 2.11.0-dev'], + ['2.11.0-entrypoint.8-g878e2a42c', '= 2.11.0-dev'], + ['2.11.0-entrypoint-17-g878e2a42c-dev', '= 2.11.0-dev'], ]; } @@ -93,7 +102,7 @@ public function testCheckFailsForInvalidConstraints(string $serverVersion, strin { $mockClient = $this->getTestDoubleClientBuilder() ->shouldHandle( - new CallRequest('box.info'), // $this->logicalOr() + new CallRequest('box.info'), TestDoubleFactory::createResponseFromData([['version' => $serverVersion]])) ->build();