1
0
Fork 0

Tweaks to also support 1.0-dev style aliases, refs #3480

pull/3657/head
Jordi Boggiano 2015-01-20 10:26:10 +00:00
parent dadf02f511
commit cd38d1e096
5 changed files with 66 additions and 24 deletions

View File

@ -176,12 +176,13 @@ class VersionParser
* @param string $branch Branch name (e.g. 2.1.x-dev)
* @return string|false Numeric prefix if present (e.g. 2.1.) or false
*/
public function parseNumericAliasPrefix($branch) {
if(preg_match('/^(?<version>(\d+\\.)*\d+).x-dev$/i', $branch, $matches)) {
public function parseNumericAliasPrefix($branch)
{
if (preg_match('/^(?<version>(\d+\\.)*\d+)(?:\.x)?-dev$/i', $branch, $matches)) {
return $matches['version'].".";
} else {
return false;
}
return false;
}
/**

View File

@ -139,6 +139,17 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
$this->assertEquals('1.0.x-dev', $package->getPrettyVersion());
$config = array(
'name' => 'A',
'version' => 'dev-master',
'extra' => array('branch-alias' => array('dev-master' => '1.0-dev')),
);
$package = $this->loader->load($config);
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
$this->assertEquals('1.0.x-dev', $package->getPrettyVersion());
$config = array(
'name' => 'B',
'version' => '4.x-dev',
@ -150,6 +161,17 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
$this->assertEquals('4.0.x-dev', $package->getPrettyVersion());
$config = array(
'name' => 'B',
'version' => '4.x-dev',
'extra' => array('branch-alias' => array('4.x-dev' => '4.0-dev')),
);
$package = $this->loader->load($config);
$this->assertInstanceOf('Composer\Package\AliasPackage', $package);
$this->assertEquals('4.0.x-dev', $package->getPrettyVersion());
$config = array(
'name' => 'C',
'version' => '4.x-dev',

View File

@ -339,6 +339,20 @@ class ValidatingArrayLoaderTest extends \PHPUnit_Framework_TestCase
),
false
),
array(
array(
'name' => 'foo/bar',
'extra' => array(
'branch-alias' => array(
'5.x-dev' => '3.1-dev'
),
)
),
array(
'extra.branch-alias.5.x-dev : the target branch (3.1-dev) is not a valid numeric alias for this version'
),
false
),
);
}
}

View File

@ -67,26 +67,6 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
return array_map($createPackage, $data);
}
/**
* @dataProvider successfulNormalizedVersions
*/
public function testNormalizeSucceeds($input, $expected)
{
$parser = new VersionParser;
$this->assertSame($expected, $parser->normalize($input));
}
public function numericAliasVersions() {
return array(
array('0.x-dev', '0.'),
array('1.0.x-dev', '1.0.'),
array('1.x-dev', '1.'),
array('1.2.x-dev', '1.2.'),
array('dev-develop', false),
array('dev-master', false),
);
}
/**
* @dataProvider numericAliasVersions
*/
@ -96,6 +76,29 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, $parser->parseNumericAliasPrefix($input));
}
public function numericAliasVersions()
{
return array(
array('0.x-dev', '0.'),
array('1.0.x-dev', '1.0.'),
array('1.x-dev', '1.'),
array('1.2.x-dev', '1.2.'),
array('1.2-dev', '1.2.'),
array('1-dev', '1.'),
array('dev-develop', false),
array('dev-master', false),
);
}
/**
* @dataProvider successfulNormalizedVersions
*/
public function testNormalizeSucceeds($input, $expected)
{
$parser = new VersionParser;
$this->assertSame($expected, $parser->normalize($input));
}
public function successfulNormalizedVersions()
{
return array(

View File

@ -113,10 +113,12 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
array('3.1.2-dev', true, 'dev', '3.1.2-dev'),
// dev packages with alias inherit the alias
array('dev-master', true, 'dev', '~2.1@dev', '2.1.x-dev'),
array('dev-master', true, 'dev', '~2.1@dev', '2.1-dev'),
array('dev-master', true, 'dev', '~2.1@dev', '2.1.3.x-dev'),
array('dev-master', true, 'dev', '~2.0@dev', '2.x-dev'),
// numeric alias
array('3.x-dev', true, 'dev', '~3.0@dev', '3.0.x-dev'),
array('3.x-dev', true, 'dev', '~3.0@dev', '3.0-dev'),
);
}