1
0
Fork 0

Fix implementation to fix tests, fixes #11220

pull/11218/head
Jordi Boggiano 2022-12-17 22:49:59 +01:00
parent caebfe14ee
commit 7f9638f65a
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 9 additions and 2 deletions

View File

@ -34,6 +34,7 @@ class VersionBumper
* For example: * For example:
* * ^1.0 + 1.2.1 -> ^1.2.1 * * ^1.0 + 1.2.1 -> ^1.2.1
* * ^1.2 + 1.2.0 -> ^1.2 * * ^1.2 + 1.2.0 -> ^1.2
* * ^1.2.0 + 1.3.0 -> ^1.3.0
* * ^1.2 || ^2.3 + 1.3.0 -> ^1.3 || ^2.3 * * ^1.2 || ^2.3 + 1.3.0 -> ^1.3 || ^2.3
* * ^1.2 || ^2.3 + 2.4.0 -> ^1.2 || ^2.4 * * ^1.2 || ^2.3 + 2.4.0 -> ^1.2 || ^2.4
* * ^3@dev + 3.2.99999-dev -> ^3.2@dev * * ^3@dev + 3.2.99999-dev -> ^3.2@dev
@ -89,7 +90,11 @@ class VersionBumper
if (Preg::isMatchAllWithOffsets($pattern, $prettyConstraint, $matches)) { if (Preg::isMatchAllWithOffsets($pattern, $prettyConstraint, $matches)) {
$modified = $prettyConstraint; $modified = $prettyConstraint;
foreach (array_reverse($matches['constraint']) as $match) { foreach (array_reverse($matches['constraint']) as $match) {
$modified = substr_replace($modified, $newPrettyConstraint, $match[1], Platform::strlen((string) $match[0])); $suffix = '';
if (substr_count($match[0], '.') === 2 && substr_count($newPrettyConstraint, '.') === 1) {
$suffix = '.0';
}
$modified = substr_replace($modified, $newPrettyConstraint.$suffix, $match[1], Platform::strlen((string) $match[0]));
} }
// if it is strictly equal to the previous one then no need to change anything // if it is strictly equal to the previous one then no need to change anything

View File

@ -51,13 +51,15 @@ class VersionBumperTest extends TestCase
yield 'preserve multi constraints' => ['^1.2 || ^2.3', '1.3.2', '^1.3.2 || ^2.3']; yield 'preserve multi constraints' => ['^1.2 || ^2.3', '1.3.2', '^1.3.2 || ^2.3'];
yield 'preserve multi constraints/2' => ['^1.2 || ^2.3', '2.4.0', '^1.2 || ^2.4']; yield 'preserve multi constraints/2' => ['^1.2 || ^2.3', '2.4.0', '^1.2 || ^2.4'];
yield 'preserve multi constraints/3' => ['^1.2 || ^2.3 || ^2', '2.4.0', '^1.2 || ^2.4 || ^2.4']; yield 'preserve multi constraints/3' => ['^1.2 || ^2.3 || ^2', '2.4.0', '^1.2 || ^2.4 || ^2.4'];
yield 'preserve multi constraints/4' => ['^1.2 || ^2.3.3 || ^2', '2.4.0', '^1.2 || ^2.4.0 || ^2.4'];
yield '@dev is preserved' => ['^3@dev', '3.2.x-dev', '^3.2@dev']; yield '@dev is preserved' => ['^3@dev', '3.2.x-dev', '^3.2@dev'];
yield 'non-stable versions abort upgrades' => ['~2', '2.1-beta.1', '~2']; yield 'non-stable versions abort upgrades' => ['~2', '2.1-beta.1', '~2'];
yield 'dev reqs are skipped' => ['dev-main', 'dev-foo', 'dev-main']; yield 'dev reqs are skipped' => ['dev-main', 'dev-foo', 'dev-main'];
yield 'dev version does not upgrade' => ['^3.2', 'dev-main', '^3.2']; yield 'dev version does not upgrade' => ['^3.2', 'dev-main', '^3.2'];
yield 'upgrade dev version if aliased' => ['^3.2', 'dev-main', '^3.3', '3.3.x-dev']; yield 'upgrade dev version if aliased' => ['^3.2', 'dev-main', '^3.3', '3.3.x-dev'];
yield 'upgrade major wildcard to caret' => ['2.*', '2.4.0', '^2.4']; yield 'upgrade major wildcard to caret' => ['2.*', '2.4.0', '^2.4'];
yield 'upgrade major wildcard as x to caret' => ['2.x.x', '2.4.0', '^2.4']; yield 'upgrade major wildcard as x to caret' => ['2.x', '2.4.0', '^2.4'];
yield 'upgrade major wildcard as x to caret/2' => ['2.x.x', '2.4.0', '^2.4.0'];
yield 'leave minor wildcard alone' => ['2.4.*', '2.4.3', '2.4.*']; yield 'leave minor wildcard alone' => ['2.4.*', '2.4.3', '2.4.*'];
yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*']; yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*'];
yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3']; yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3'];