diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 3925e7e65..d546b2655 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -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('/^(?(\d+\\.)*\d+).x-dev$/i', $branch, $matches)) { + public function parseNumericAliasPrefix($branch) + { + if (preg_match('/^(?(\d+\\.)*\d+)(?:\.x)?-dev$/i', $branch, $matches)) { return $matches['version']."."; - } else { - return false; } + + return false; } /** diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index 4b98ae26d..1491571a1 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -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', diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 2b0829759..32c55bd40 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -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 + ), ); } } diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index c52ec1382..13920e2f0 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -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( diff --git a/tests/Composer/Test/Package/Version/VersionSelectorTest.php b/tests/Composer/Test/Package/Version/VersionSelectorTest.php index fb3a6f666..6feb207a7 100644 --- a/tests/Composer/Test/Package/Version/VersionSelectorTest.php +++ b/tests/Composer/Test/Package/Version/VersionSelectorTest.php @@ -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'), ); }