2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2017-09-26 13:06:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\VersionParser;
|
2020-02-07 03:18:45 +00:00
|
|
|
use Composer\Test\TestCase;
|
2017-09-26 13:06:39 +00:00
|
|
|
|
2017-11-04 14:52:13 +00:00
|
|
|
class VersionParserTest extends TestCase
|
2017-09-26 13:06:39 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-11-01 20:44:12 +00:00
|
|
|
* @dataProvider provideParseNameVersionPairsData
|
|
|
|
*
|
|
|
|
* @param string[] $pairs
|
|
|
|
* @param array<array<string, string>> $result
|
2017-09-26 13:06:39 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testParseNameVersionPairs(array $pairs, array $result): void
|
2017-09-26 13:06:39 +00:00
|
|
|
{
|
|
|
|
$versionParser = new VersionParser();
|
|
|
|
|
|
|
|
$this->assertSame($result, $versionParser->parseNameVersionPairs($pairs));
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideParseNameVersionPairsData(): array
|
2017-09-26 13:06:39 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
[['php:^7.0'], [['name' => 'php', 'version' => '^7.0']]],
|
|
|
|
[['php', '^7.0'], [['name' => 'php', 'version' => '^7.0']]],
|
|
|
|
[['php', 'ext-apcu'], [['name' => 'php'], ['name' => 'ext-apcu']]],
|
|
|
|
[['foo/*', 'bar*', 'acme/baz', '*@dev'], [['name' => 'foo/*'], ['name' => 'bar*'], ['name' => 'acme/baz', 'version' => '*@dev']]],
|
|
|
|
[['php', '*'], [['name' => 'php', 'version' => '*']]],
|
|
|
|
];
|
2017-09-26 13:06:39 +00:00
|
|
|
}
|
2018-04-13 11:48:30 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-01 20:44:12 +00:00
|
|
|
* @dataProvider provideIsUpgradeTests
|
2018-04-13 11:48:30 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testIsUpgrade(string $from, string $to, bool $expected): void
|
2018-04-13 11:48:30 +00:00
|
|
|
{
|
|
|
|
$this->assertSame($expected, VersionParser::isUpgrade($from, $to));
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
public static function provideIsUpgradeTests(): array
|
2018-04-13 11:48:30 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
return [
|
|
|
|
['0.9.0.0', '1.0.0.0', true],
|
|
|
|
['1.0.0.0', '0.9.0.0', false],
|
|
|
|
['1.0.0.0', VersionParser::DEFAULT_BRANCH_ALIAS, true],
|
|
|
|
[VersionParser::DEFAULT_BRANCH_ALIAS, VersionParser::DEFAULT_BRANCH_ALIAS, true],
|
|
|
|
[VersionParser::DEFAULT_BRANCH_ALIAS, '1.0.0.0', false],
|
|
|
|
['1.0.0.0', 'dev-foo', true],
|
|
|
|
['dev-foo', 'dev-foo', true],
|
|
|
|
['dev-foo', '1.0.0.0', true],
|
|
|
|
];
|
2018-04-13 11:48:30 +00:00
|
|
|
}
|
2017-09-26 13:06:39 +00:00
|
|
|
}
|