Merge branch 'master' of https://github.com/composer/composer into autoload
* 'master' of https://github.com/composer/composer: Add a few solver tests regarding "replace" Fix missing support for the symfony-bundle package type. Fix up version parsing Add some more version normalization and support for branch namespull/44/head
commit
4d7e012e2f
|
@ -27,6 +27,7 @@ $dm->setDownloader('zip', new Downloader\ZipDownloader());
|
||||||
// initialize installation manager
|
// initialize installation manager
|
||||||
$im = new Installer\InstallationManager();
|
$im = new Installer\InstallationManager();
|
||||||
$im->setInstaller('library', new Installer\LibraryInstaller('vendor', $dm, $rm->getLocalRepository()));
|
$im->setInstaller('library', new Installer\LibraryInstaller('vendor', $dm, $rm->getLocalRepository()));
|
||||||
|
$im->setInstaller('symfony-bundle', new Installer\LibraryInstaller('vendor/bundles', $dm, $rm->getLocalRepository()));
|
||||||
|
|
||||||
// load package
|
// load package
|
||||||
$loader = new Package\Loader\JsonLoader();
|
$loader = new Package\Loader\JsonLoader();
|
||||||
|
|
|
@ -34,6 +34,10 @@ class VersionParser
|
||||||
{
|
{
|
||||||
$version = trim($version);
|
$version = trim($version);
|
||||||
|
|
||||||
|
if (preg_match('{^(?:master|trunk)(?:[.-]?dev)?$}i', $version)) {
|
||||||
|
return '9999999-dev';
|
||||||
|
}
|
||||||
|
|
||||||
// match classical versioning
|
// match classical versioning
|
||||||
if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.$this->modifierRegex.'$}i', $version, $matches)) {
|
if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.$this->modifierRegex.'$}i', $version, $matches)) {
|
||||||
$version = $matches[1]
|
$version = $matches[1]
|
||||||
|
@ -62,9 +66,40 @@ class VersionParser
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preg_match('{(.*?)[.-]?dev$}i', $version, $match)) {
|
||||||
|
try {
|
||||||
|
return $this->normalizeBranch($match[1]);
|
||||||
|
} catch (\Exception $e) {}
|
||||||
|
}
|
||||||
|
|
||||||
throw new \UnexpectedValueException('Invalid version string '.$version);
|
throw new \UnexpectedValueException('Invalid version string '.$version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes a branch name to be able to perform comparisons on it
|
||||||
|
*
|
||||||
|
* @param string $version
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function normalizeBranch($name)
|
||||||
|
{
|
||||||
|
$name = trim($name);
|
||||||
|
|
||||||
|
if (in_array($name, array('master', 'trunk'))) {
|
||||||
|
return $this->normalize($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('#^v?(\d+)(\.(?:\d+|[x*]))?(\.(?:\d+|[x*]))?(\.(?:\d+|[x*]))?$#i', $name, $matches)) {
|
||||||
|
$version = '';
|
||||||
|
for ($i = 1; $i < 5; $i++) {
|
||||||
|
$version .= isset($matches[$i]) ? str_replace('*', 'x', $matches[$i]) : '.x';
|
||||||
|
}
|
||||||
|
return str_replace('x', '9999999', $version).'-dev';
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \UnexpectedValueException('Invalid branch name '.$branch);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses as constraint string into LinkConstraint objects
|
* Parses as constraint string into LinkConstraint objects
|
||||||
*
|
*
|
||||||
|
@ -93,7 +128,7 @@ class VersionParser
|
||||||
|
|
||||||
private function parseConstraint($constraint)
|
private function parseConstraint($constraint)
|
||||||
{
|
{
|
||||||
if ('*' === $constraint || '*.*' === $constraint || '*.*.*' === $constraint) {
|
if ('*' === $constraint || '*.*' === $constraint || '*.*.*' === $constraint || '*.*.*.*' === $constraint) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,10 +152,11 @@ class VersionParser
|
||||||
}
|
}
|
||||||
|
|
||||||
// match operators constraints
|
// match operators constraints
|
||||||
if (preg_match('{^(>=?|<=?|==?)?\s*(\d+.*)}', $constraint, $matches)) {
|
if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
|
||||||
|
try {
|
||||||
$version = $this->normalize($matches[2]);
|
$version = $this->normalize($matches[2]);
|
||||||
|
|
||||||
return array(new VersionConstraint($matches[1] ?: '=', $version));
|
return array(new VersionConstraint($matches[1] ?: '=', $version));
|
||||||
|
} catch (\Exception $e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \UnexpectedValueException('Could not parse version constraint '.$constraint);
|
throw new \UnexpectedValueException('Could not parse version constraint '.$constraint);
|
||||||
|
|
|
@ -231,6 +231,60 @@ class SolverTest extends \PHPUnit_Framework_TestCase
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSkipReplacerOfExistingPackage()
|
||||||
|
{
|
||||||
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
||||||
|
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
|
||||||
|
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
|
||||||
|
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
|
||||||
|
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
|
||||||
|
|
||||||
|
$this->reposComplete();
|
||||||
|
|
||||||
|
$this->request->install('A');
|
||||||
|
|
||||||
|
$this->checkSolverResult(array(
|
||||||
|
array('job' => 'install', 'package' => $packageB),
|
||||||
|
array('job' => 'install', 'package' => $packageA),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInstallReplacerOfMissingPackage()
|
||||||
|
{
|
||||||
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
||||||
|
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
|
||||||
|
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
|
||||||
|
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
|
||||||
|
|
||||||
|
$this->reposComplete();
|
||||||
|
|
||||||
|
$this->request->install('A');
|
||||||
|
|
||||||
|
$this->checkSolverResult(array(
|
||||||
|
array('job' => 'install', 'package' => $packageQ),
|
||||||
|
array('job' => 'install', 'package' => $packageA),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSkipReplacedPackageIfReplacerIsSelected()
|
||||||
|
{
|
||||||
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
||||||
|
$this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
|
||||||
|
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
|
||||||
|
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
|
||||||
|
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
|
||||||
|
|
||||||
|
$this->reposComplete();
|
||||||
|
|
||||||
|
$this->request->install('A');
|
||||||
|
$this->request->install('Q');
|
||||||
|
|
||||||
|
$this->checkSolverResult(array(
|
||||||
|
array('job' => 'install', 'package' => $packageQ),
|
||||||
|
array('job' => 'install', 'package' => $packageA),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public function testInstallCircularRequire()
|
public function testInstallCircularRequire()
|
||||||
{
|
{
|
||||||
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
||||||
|
|
|
@ -49,6 +49,9 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
'parses datetime' => array('20100102-203040', '20100102-203040'),
|
'parses datetime' => array('20100102-203040', '20100102-203040'),
|
||||||
'parses dt+number' => array('20100102203040-10', '20100102203040-10'),
|
'parses dt+number' => array('20100102203040-10', '20100102203040-10'),
|
||||||
'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'),
|
'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'),
|
||||||
|
'parses master' => array('master', '9999999-dev'),
|
||||||
|
'parses trunk' => array('trunk', '9999999-dev'),
|
||||||
|
'parses trunk/2' => array('trunk-dev', '9999999-dev'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +75,30 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider successfulNormalizedBranches
|
||||||
|
*/
|
||||||
|
public function testNormalizeBranch($input, $expected)
|
||||||
|
{
|
||||||
|
$parser = new VersionParser;
|
||||||
|
$this->assertSame((string) $expected, (string) $parser->normalizeBranch($input));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function successfulNormalizedBranches()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'parses x' => array('v1.x', '1.9999999.9999999.9999999-dev'),
|
||||||
|
'parses *' => array('v1.*', '1.9999999.9999999.9999999-dev'),
|
||||||
|
'parses digits' => array('v1.0', '1.0.9999999.9999999-dev'),
|
||||||
|
'parses long x' => array('v1.0.x', '1.0.9999999.9999999-dev'),
|
||||||
|
'parses long *' => array('v1.0.3.*', '1.0.3.9999999-dev'),
|
||||||
|
'parses long digits' => array('v2.4.0', '2.4.0.9999999-dev'),
|
||||||
|
'parses long digits/2' => array('2.4.4', '2.4.4.9999999-dev'),
|
||||||
|
'parses master' => array('master', '9999999-dev'),
|
||||||
|
'parses trunk' => array('trunk', '9999999-dev'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider simpleConstraints
|
* @dataProvider simpleConstraints
|
||||||
*/
|
*/
|
||||||
|
@ -93,6 +120,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
'no op means eq' => array('1.2.3', new VersionConstraint('=', '1.2.3.0')),
|
'no op means eq' => array('1.2.3', new VersionConstraint('=', '1.2.3.0')),
|
||||||
'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')),
|
'completes version' => array('=1.0', new VersionConstraint('=', '1.0.0.0')),
|
||||||
'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')),
|
'accepts spaces' => array('>= 1.2.3', new VersionConstraint('>=', '1.2.3.0')),
|
||||||
|
'accepts master' => array('>=master-dev', new VersionConstraint('>=', '9999999-dev')),
|
||||||
|
'accepts master/2' => array('master-dev', new VersionConstraint('=', '9999999-dev')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue