2022-06-09 09:43:59 +00:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Package\Version;
|
|
|
|
|
|
|
|
use Composer\Package\Version\VersionBumper;
|
|
|
|
use Composer\Package\Package;
|
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
use Generator;
|
|
|
|
|
|
|
|
class VersionBumperTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideBumpRequirementTests
|
|
|
|
*/
|
|
|
|
public function testBumpRequirement(string $requirement, string $prettyVersion, string $expectedRequirement, ?string $branchAlias = null): void
|
|
|
|
{
|
|
|
|
$versionBumper = new VersionBumper();
|
|
|
|
$versionParser = new VersionParser();
|
|
|
|
|
|
|
|
$package = new Package('foo/bar', $versionParser->normalize($prettyVersion), $prettyVersion);
|
|
|
|
|
|
|
|
if ($branchAlias !== null) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$package->setExtra(['branch-alias' => [$prettyVersion => $branchAlias]]);
|
2022-06-09 09:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$newConstraint = $versionBumper->bumpRequirement($versionParser->parseConstraints($requirement), $package);
|
|
|
|
|
|
|
|
// assert that the recommended version is what we expect
|
|
|
|
$this->assertSame($expectedRequirement, $newConstraint);
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideBumpRequirementTests(): Generator
|
2022-06-09 09:43:59 +00:00
|
|
|
{
|
|
|
|
// constraint, version, expected recommendation, [branch-alias]
|
|
|
|
yield 'upgrade caret' => ['^1.0', '1.2.1', '^1.2.1'];
|
|
|
|
yield 'skip trailing .0s' => ['^1.0', '1.0.0', '^1.0'];
|
|
|
|
yield 'skip trailing .0s/2' => ['^1.2', '1.2.0', '^1.2'];
|
2022-12-12 11:59:26 +00:00
|
|
|
yield 'preserve major.minor.patch format when installed minor is 0' => ['^1.0.0', '1.2.0', '^1.2.0'];
|
|
|
|
yield 'preserve major.minor.patch format when installed minor is 1' => ['^1.0.0', '1.2.1', '^1.2.1'];
|
2022-06-09 09:43:59 +00:00
|
|
|
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/3' => ['^1.2 || ^2.3 || ^2', '2.4.0', '^1.2 || ^2.4 || ^2.4'];
|
2022-12-17 21:49:59 +00:00
|
|
|
yield 'preserve multi constraints/4' => ['^1.2 || ^2.3.3 || ^2', '2.4.0', '^1.2 || ^2.4.0 || ^2.4'];
|
2022-06-09 09:43:59 +00:00
|
|
|
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 'dev reqs are skipped' => ['dev-main', 'dev-foo', 'dev-main'];
|
|
|
|
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 major wildcard to caret' => ['2.*', '2.4.0', '^2.4'];
|
2022-12-17 21:49:59 +00:00
|
|
|
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'];
|
2022-06-09 09:43:59 +00:00
|
|
|
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 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3'];
|
2023-08-31 09:05:49 +00:00
|
|
|
yield 'update patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.6'];
|
|
|
|
yield 'leave extra-only-tilde alone' => ['~2.2.3.1', '2.2.4.5', '~2.2.3.1'];
|
2022-12-17 21:58:35 +00:00
|
|
|
yield 'upgrade bigger-or-eq to latest' => ['>=3.0', '3.4.5', '>=3.4.5'];
|
|
|
|
yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3'];
|
2022-06-09 09:43:59 +00:00
|
|
|
}
|
|
|
|
}
|