1
0
Fork 0

Allow parsing of stability modifiers combined with multi-constraints

pull/1184/merge
Jordi Boggiano 2012-10-05 19:05:39 +02:00
parent b3077bc4bc
commit 62bb5b339b
2 changed files with 20 additions and 0 deletions

View File

@ -234,6 +234,13 @@ class VersionParser
private function parseConstraint($constraint)
{
if (preg_match('{^([^,\s]+?)@('.implode('|', array_keys(BasePackage::$stabilities)).')$}i', $constraint, $match)) {
$constraint = $match[1];
if ($match[2] !== 'stable') {
$stabilityModifier = $match[2];
}
}
if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) {
return array();
}
@ -274,6 +281,10 @@ class VersionParser
try {
$version = $this->normalize($matches[2]);
if (!empty($stabilityModifier) && $this->parseStability($version) === 'stable') {
$version .= '-' . $stabilityModifier;
}
return array(new VersionConstraint($matches[1] ?: '=', $version));
} catch (\Exception $e) {}
}

View File

@ -249,6 +249,15 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0,<=3.0'));
}
public function testParseConstraintsMultiWithStabilities()
{
$parser = new VersionParser;
$first = new VersionConstraint('>', '2.0.0.0');
$second = new VersionConstraint('<=', '3.0.0.0-dev');
$multi = new MultiConstraint(array($first, $second));
$this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0@stable,<=3.0@dev'));
}
/**
* @dataProvider failingConstraints
* @expectedException UnexpectedValueException