From 8ba2045df48ee393ecd78dd48c080bab3ea178b3 Mon Sep 17 00:00:00 2001 From: Arne Blankerts Date: Wed, 31 Jan 2024 23:42:43 +0100 Subject: [PATCH] Implement #35 --- src/Version.php | 5 +++-- .../VersionConstraintParserTest.php | 20 +++++++++++++++++++ tests/Unit/VersionTest.php | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Version.php b/src/Version.php index 644af5c..de47040 100644 --- a/src/Version.php +++ b/src/Version.php @@ -162,7 +162,7 @@ public function getBuildMetaData(): BuildMetaData { */ private function parseVersion(array $matches): void { $this->major = new VersionNumber((int)$matches['Major']); - $this->minor = new VersionNumber((int)$matches['Minor']); + $this->minor = isset($matches['Minor']) ? new VersionNumber((int)$matches['Minor']) : new VersionNumber(0); $this->patch = isset($matches['Patch']) ? new VersionNumber((int)$matches['Patch']) : new VersionNumber(0); if (isset($matches['PreReleaseSuffix']) && $matches['PreReleaseSuffix'] !== '') { @@ -182,8 +182,9 @@ private function parseVersion(array $matches): void { private function ensureVersionStringIsValid($version): void { $regex = '/^v? (?P0|[1-9]\d*) - \\. + (\\. (?P0|[1-9]\d*) + )? (\\. (?P0|[1-9]\d*) )? diff --git a/tests/Integration/VersionConstraintParserTest.php b/tests/Integration/VersionConstraintParserTest.php index 729b430..699d3e7 100644 --- a/tests/Integration/VersionConstraintParserTest.php +++ b/tests/Integration/VersionConstraintParserTest.php @@ -156,6 +156,26 @@ public function versionStringProvider(): array { new SpecificMajorVersionConstraint('^3.0.0-alpha.1', 3) ] ) + ], + [ + '^1.0', + new AndVersionConstraintGroup( + '^1.0', + [ + new GreaterThanOrEqualToVersionConstraint('^1.0', new Version('1.0')), + new SpecificMajorVersionConstraint('^1.0', 1) + ] + ) + ], + [ + '^1', + new AndVersionConstraintGroup( + '^1', + [ + new GreaterThanOrEqualToVersionConstraint('^1', new Version('1')), + new SpecificMajorVersionConstraint('^1', 1) + ] + ) ] ]; } diff --git a/tests/Unit/VersionTest.php b/tests/Unit/VersionTest.php index 38eb1f6..0a57fa5 100644 --- a/tests/Unit/VersionTest.php +++ b/tests/Unit/VersionTest.php @@ -147,7 +147,8 @@ public function versionStringProvider() { ['v1.2.3-beta.2', '1.2.3-beta.2'], ['0.1', '0.1.0'], - ['v0.1', '0.1.0'] + ['v0.1', '0.1.0'], + ['1', '1.0.0'] ]; }