diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index fcdef2364..87769066f 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -70,6 +70,10 @@ class RootPackageLoader extends ArrayLoader $realPackage = $package->getAliasOf(); } + if (isset($config['minimum-stability'])) { + $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); + } + $aliases = array(); $stabilityFlags = array(); $references = array(); @@ -82,7 +86,7 @@ class RootPackageLoader extends ArrayLoader $links[$link->getTarget()] = $link->getConstraint()->getPrettyString(); } $aliases = $this->extractAliases($links, $aliases); - $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags); + $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability()); $references = $this->extractReferences($links, $references); } } @@ -91,10 +95,6 @@ class RootPackageLoader extends ArrayLoader $realPackage->setStabilityFlags($stabilityFlags); $realPackage->setReferences($references); - if (isset($config['minimum-stability'])) { - $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); - } - if (isset($config['prefer-stable'])) { $realPackage->setPreferStable((bool) $config['prefer-stable']); } @@ -124,11 +124,12 @@ class RootPackageLoader extends ArrayLoader return $aliases; } - private function extractStabilityFlags(array $requires, array $stabilityFlags) + private function extractStabilityFlags(array $requires, array $stabilityFlags, $minimumStability) { $stabilities = BasePackage::$stabilities; + $minimumStability = $stabilities[$minimumStability]; foreach ($requires as $reqName => $reqVersion) { - // parse explicit stability flags + // parse explicit stability flags to the most unstable if (preg_match('{^[^,\s]*?@('.implode('|', array_keys($stabilities)).')$}i', $reqVersion, $match)) { $name = strtolower($reqName); $stability = $stabilities[VersionParser::normalizeStability($match[1])]; @@ -141,12 +142,13 @@ class RootPackageLoader extends ArrayLoader continue; } - // infer flags for requirements that have an explicit -dev or -beta version specified for example + // infer flags for requirements that have an explicit -dev or -beta version specified but only + // for those that are more unstable than the minimumStability or existing flags $reqVersion = preg_replace('{^([^,\s@]+) as .+$}', '$1', $reqVersion); if (preg_match('{^[^,\s@]+$}', $reqVersion) && 'stable' !== ($stabilityName = VersionParser::parseStability($reqVersion))) { $name = strtolower($reqName); $stability = $stabilities[$stabilityName]; - if (isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) { + if ((isset($stabilityFlags[$name]) && $stabilityFlags[$name] > $stability) || ($minimumStability > $stability)) { continue; } $stabilityFlags[$name] = $stability; diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 6f4f53e19..e1a8781a1 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -14,6 +14,7 @@ namespace Composer\Test\Package\Loader; use Composer\Config; use Composer\Package\Loader\RootPackageLoader; +use Composer\Package\BasePackage; use Composer\Test\Mock\ProcessExecutorMock; use Composer\Repository\RepositoryManager; @@ -49,4 +50,40 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals("dev-$commitHash", $package->getVersion()); } + + protected function loadPackage($data) + { + $manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') + ->disableOriginalConstructor() + ->getMock(); + + $processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) { + return 1; + }); + + $config = new Config; + $config->merge(array('repositories' => array('packagist' => false))); + + $loader = new RootPackageLoader($manager, $config); + + return $loader->load($data); + } + + public function testStabilityFlagsParsing() + { + $package = $this->loadPackage(array( + 'require' => array( + 'foo/bar' => '~2.1.0-beta2', + 'bar/baz' => '1.0.x-dev as 1.2.0', + 'qux/quux' => '1.0.*@rc', + ), + 'minimum-stability' => 'alpha', + )); + + $this->assertEquals('alpha', $package->getMinimumStability()); + $this->assertEquals(array( + 'bar/baz' => BasePackage::STABILITY_DEV, + 'qux/quux' => BasePackage::STABILITY_RC, + ), $package->getStabilityFlags()); + } }