diff --git a/core/Version.php b/core/Version.php index 3e7f8f9a40c..3172e3d8fba 100644 --- a/core/Version.php +++ b/core/Version.php @@ -73,10 +73,31 @@ public function nextPreviewVersion($version): string } return ''; } elseif ($this->isStableVersion($version)) { - // no suffix yet - return $version . '-alpha.' . $dt; + // no suffix yet, we need to bump the patch first + $newVersion = preg_replace_callback( + '/^(\d+\.\d+\.)(\d+)$/', + function ($matches) { + $matches[2] = $matches[2] + 1; + return $matches[1] . $matches[2]; + }, + $version + ); + + return sprintf('%s-alpha.%s', $newVersion, $dt); + } elseif ('alpha' === substr($version, -5)) { + // -alpha + return $version . '.' . $dt; } else { - // -b1, -rc1, -alpha + // -b1, -rc1 + $newVersion = preg_replace_callback( + '^(\d+\.\d+\.\d+-(?:rc|b|beta))(\d+)$/i', + function ($matches) { + $matches[2] = $matches[2] + 1; + return $matches[1] . $matches[2]; + }, + $version + ); + return $version . '.' . $dt; } } diff --git a/tests/PHPUnit/Unit/VersionTest.php b/tests/PHPUnit/Unit/VersionTest.php index 4fc87cd5353..1177c4f8270 100644 --- a/tests/PHPUnit/Unit/VersionTest.php +++ b/tests/PHPUnit/Unit/VersionTest.php @@ -104,6 +104,23 @@ public function testNextPreviewVersion() $this->assertNextVersionExists('3.3.3-rc1.20201224180000'); } + public function testNextPreviewCorrectlyBumpsVersionIfNeeded() + { + // stable bumps patch and adds alpha + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3', '3.3.4-alpha'); + + // non-stable bumps b1, rc1 + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1', '3.3.3-b2'); + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1', '3.3.3-rc2'); + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1.20201224180000', '3.3.3-b1'); + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1.20201224180000', '3.3.3-rc1'); + + // preview does not bump x.y.z, only dt suffix + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-alpha-20201224180000', '3.3.3-alpha'); + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-b1.20201224180000', '3.3.3-b1'); + $this->assertCorrectPreviewVersionWithoutSuffix('3.3.3-rc1.20201224180000', '3.3.3-rc1'); + } + private function assertIsStableVersion($versionNumber) { $isStable = $this->version->isStableVersion($versionNumber); @@ -152,10 +169,18 @@ private function assertNextVersionExists($versionNumber) $this->assertTrue($this->version->isPreviewVersion($nextVersionNumber)); } + private function assertCorrectPreviewVersionWithoutSuffix($versionNumber, $newVersionNumber) + { + $this->assertStringMatchesFormat( + "/^$newVersionNumber.\d{14}$/", + $this->version->nextPreviewVersion($versionNumber) + ); + } + /** * @dataProvider getLowerVersionCompares */ - public function testVersionContraints($v1, $v2) + public function testVersionConstraints($v1, $v2) { $v = new VersionParser(); $v1p = $v->parseConstraints($v1);