Add getVersionConstraint test case to avoid version normalization issues

main
Nils Adermann 13 years ago
parent af408eee9a
commit 3b06a22e69

@ -61,7 +61,7 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
$this->reposComplete(); $this->reposComplete();
@ -123,12 +123,12 @@ class SolverTest extends TestCase
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$this->reposComplete(); $this->reposComplete();
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0.0.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0.0.0'), 'requires')));
$this->request->install('A', new VersionConstraint('=', '1.0.0.0')); $this->request->install('A', $this->getVersionConstraint('=', '1.0.0.0'));
$this->request->install('B', new VersionConstraint('=', '1.1.0.0')); $this->request->install('B', $this->getVersionConstraint('=', '1.1.0.0'));
$this->request->update('A', new VersionConstraint('=', '1.0.0.0')); $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
$this->request->update('B', new VersionConstraint('=', '1.0.0.0')); $this->request->update('B', $this->getVersionConstraint('=', '1.0.0.0'));
$this->checkSolverResult(array( $this->checkSolverResult(array(
array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB), array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
@ -182,7 +182,7 @@ class SolverTest extends TestCase
$this->repo->addPackage($this->getPackage('A', '2.0')); $this->repo->addPackage($this->getPackage('A', '2.0'));
$this->reposComplete(); $this->reposComplete();
$this->request->install('A', new VersionConstraint('<', '2.0.0.0')); $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
$this->request->update('A'); $this->request->update('A');
$this->checkSolverResult(array(array( $this->checkSolverResult(array(array(
@ -199,8 +199,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($this->getPackage('A', '2.0')); $this->repo->addPackage($this->getPackage('A', '2.0'));
$this->reposComplete(); $this->reposComplete();
$this->request->install('A', new VersionConstraint('<', '2.0.0.0')); $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
$this->request->update('A', new VersionConstraint('=', '1.0.0.0')); $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
$this->checkSolverResult(array(array( $this->checkSolverResult(array(array(
'job' => 'update', 'job' => 'update',
@ -217,8 +217,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($this->getPackage('A', '2.0')); $this->repo->addPackage($this->getPackage('A', '2.0'));
$this->reposComplete(); $this->reposComplete();
$this->request->install('A', new VersionConstraint('<', '2.0.0.0')); $this->request->install('A', $this->getVersionConstraint('<', '2.0.0.0'));
$this->request->update('A', new VersionConstraint('=', '1.0.0.0')); $this->request->update('A', $this->getVersionConstraint('=', '1.0.0.0'));
$this->checkSolverResult(array(array( $this->checkSolverResult(array(array(
'job' => 'update', 'job' => 'update',
@ -237,7 +237,7 @@ class SolverTest extends TestCase
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$this->repo->addPackage($packageC = $this->getPackage('C', '1.1')); $this->repo->addPackage($packageC = $this->getPackage('C', '1.1'));
$this->repo->addPackage($this->getPackage('D', '1.0')); $this->repo->addPackage($this->getPackage('D', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
$this->reposComplete(); $this->reposComplete();
@ -259,8 +259,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($middlePackageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($middlePackageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
$this->repo->addPackage($oldPackageB = $this->getPackage('B', '0.9')); $this->repo->addPackage($oldPackageB = $this->getPackage('B', '0.9'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
$packageA->setConflicts(array(new Link('A', 'B', new VersionConstraint('<', '1.0'), 'conflicts'))); $packageA->setConflicts(array(new Link('A', 'B', $this->getVersionConstraint('<', '1.0'), 'conflicts')));
$this->reposComplete(); $this->reposComplete();
@ -306,8 +306,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0')); $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '0.8')); $this->repo->addPackage($packageB = $this->getPackage('B', '0.8'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setProvides(array(new Link('Q', 'B', new VersionConstraint('=', '1.0'), 'provides'))); $packageQ->setProvides(array(new Link('Q', 'B', $this->getVersionConstraint('=', '1.0'), 'provides')));
$this->reposComplete(); $this->reposComplete();
@ -324,8 +324,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0')); $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces'))); $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
$this->reposComplete(); $this->reposComplete();
@ -341,8 +341,8 @@ class SolverTest extends TestCase
{ {
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0')); $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces'))); $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
$this->reposComplete(); $this->reposComplete();
@ -359,8 +359,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0')); $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces'))); $packageQ->setReplaces(array(new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
$this->reposComplete(); $this->reposComplete();
@ -377,24 +377,24 @@ class SolverTest extends TestCase
{ {
$this->repo->addPackage($packageX = $this->getPackage('X', '1.0')); $this->repo->addPackage($packageX = $this->getPackage('X', '1.0'));
$packageX->setRequires(array( $packageX->setRequires(array(
new Link('X', 'A', new VersionConstraint('>=', '2.0.0.0'), 'requires'), new Link('X', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires'),
new Link('X', 'B', new VersionConstraint('>=', '2.0.0.0'), 'requires'))); new Link('X', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires')));
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '2.0.0'));
$this->repo->addPackage($newPackageA = $this->getPackage('A', '2.1.0')); $this->repo->addPackage($newPackageA = $this->getPackage('A', '2.1.0'));
$this->repo->addPackage($newPackageB = $this->getPackage('B', '2.1.0')); $this->repo->addPackage($newPackageB = $this->getPackage('B', '2.1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '2.0.0.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires')));
// new package A depends on version of package B that does not exist // new package A depends on version of package B that does not exist
// => new package A is not installable // => new package A is not installable
$newPackageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '2.2.0.0'), 'requires'))); $newPackageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '2.2.0.0'), 'requires')));
// add a package S replacing both A and B, so that S and B or S and A cannot be simultaneously installed // add a package S replacing both A and B, so that S and B or S and A cannot be simultaneously installed
// but an alternative option for A and B both exists // but an alternative option for A and B both exists
// this creates a more difficult so solve conflict // this creates a more difficult so solve conflict
$this->repo->addPackage($packageS = $this->getPackage('S', '2.0.0')); $this->repo->addPackage($packageS = $this->getPackage('S', '2.0.0'));
$packageS->setReplaces(array(new Link('S', 'A', new VersionConstraint('>=', '2.0.0.0'), 'replaces'), new Link('S', 'B', new VersionConstraint('>=', '2.0.0.0'), 'replaces'))); $packageS->setReplaces(array(new Link('S', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces'), new Link('S', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces')));
$this->reposComplete(); $this->reposComplete();
@ -412,8 +412,8 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageB1 = $this->getPackage('B', '0.9')); $this->repo->addPackage($packageB1 = $this->getPackage('B', '0.9'));
$this->repo->addPackage($packageB2 = $this->getPackage('B', '1.1')); $this->repo->addPackage($packageB2 = $this->getPackage('B', '1.1'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageB2->setRequires(array(new Link('B', 'A', new VersionConstraint('>=', '1.0'), 'requires'))); $packageB2->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$this->reposComplete(); $this->reposComplete();
@ -433,10 +433,10 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$this->repo->addPackage($packageC = $this->getPackage('C', '1.0')); $this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
$this->repo->addPackage($packageD = $this->getPackage('D', '1.0')); $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'))); $packageA->setRequires(array(new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageB->setRequires(array(new Link('B', 'Virtual', new VersionConstraint('>=', '1.0'), 'requires'))); $packageB->setRequires(array(new Link('B', 'Virtual', $this->getVersionConstraint('>=', '1.0'), 'requires')));
$packageC->setRequires(array(new Link('C', 'Virtual', new VersionConstraint('==', '1.0'), 'provides'))); $packageC->setRequires(array(new Link('C', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
$packageD->setRequires(array(new Link('D', 'Virtual', new VersionConstraint('==', '1.0'), 'provides'))); $packageD->setRequires(array(new Link('D', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
$this->reposComplete(); $this->reposComplete();
@ -461,18 +461,18 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageD2 = $this->getPackage('D', '1.1')); $this->repo->addPackage($packageD2 = $this->getPackage('D', '1.1'));
$packageA->setRequires(array( $packageA->setRequires(array(
new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires'), new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires'),
new Link('A', 'C', new VersionConstraint('>=', '1.0'), 'requires'), new Link('A', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
)); ));
$packageD->setReplaces(array( $packageD->setReplaces(array(
new Link('D', 'B', new VersionConstraint('>=', '1.0'), 'replaces'), new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
new Link('D', 'C', new VersionConstraint('>=', '1.0'), 'replaces'), new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
)); ));
$packageD2->setReplaces(array( $packageD2->setReplaces(array(
new Link('D', 'B', new VersionConstraint('>=', '1.0'), 'replaces'), new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
new Link('D', 'C', new VersionConstraint('>=', '1.0'), 'replaces'), new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
)); ));
$this->reposComplete(); $this->reposComplete();
@ -496,23 +496,23 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageD = $this->getPackage('D', '2.0.9')); $this->repo->addPackage($packageD = $this->getPackage('D', '2.0.9'));
$packageC->setRequires(array( $packageC->setRequires(array(
new Link('C', 'A', new VersionConstraint('>=', '2.0'), 'requires'), new Link('C', 'A', $this->getVersionConstraint('>=', '2.0'), 'requires'),
new Link('C', 'D', new VersionConstraint('>=', '2.0'), 'requires'), new Link('C', 'D', $this->getVersionConstraint('>=', '2.0'), 'requires'),
)); ));
$packageD->setRequires(array( $packageD->setRequires(array(
new Link('D', 'A', new VersionConstraint('>=', '2.1'), 'requires'), new Link('D', 'A', $this->getVersionConstraint('>=', '2.1'), 'requires'),
new Link('D', 'B', new VersionConstraint('>=', '2.0-dev'), 'requires'), new Link('D', 'B', $this->getVersionConstraint('>=', '2.0-dev'), 'requires'),
)); ));
$packageB1->setRequires(array(new Link('B', 'A', new VersionConstraint('==', '2.1.0.0-dev'), 'requires'))); $packageB1->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
$packageB2->setRequires(array(new Link('B', 'A', new VersionConstraint('==', '2.1.0.0-dev'), 'requires'))); $packageB2->setRequires(array(new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
$packageB2->setReplaces(array(new Link('B', 'D', new VersionConstraint('==', '2.0.9.0'), 'replaces'))); $packageB2->setReplaces(array(new Link('B', 'D', $this->getVersionConstraint('==', '2.0.9.0'), 'replaces')));
$this->reposComplete(); $this->reposComplete();
$this->request->install('C', new VersionConstraint('==', '2.0.0.0-dev')); $this->request->install('C', $this->getVersionConstraint('==', '2.0.0.0-dev'));
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
@ -525,7 +525,7 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));; $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));;
$packageA->setConflicts(array( $packageA->setConflicts(array(
new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'conflicts'), new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'conflicts'),
)); ));
$this->reposComplete(); $this->reposComplete();
@ -547,7 +547,7 @@ class SolverTest extends TestCase
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0')); $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
$packageA->setRequires(array( $packageA->setRequires(array(
new Link('A', 'B', new VersionConstraint('>=', '2.0'), 'requires'), new Link('A', 'B', $this->getVersionConstraint('>=', '2.0'), 'requires'),
)); ));
$this->reposComplete(); $this->reposComplete();

@ -27,6 +27,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
} }
} }
protected function getVersionConstraint($operator, $version)
{
return new VersionConstraint(
$operator,
self::$versionParser->normalize($version)
);
}
protected function getPackage($name, $version) protected function getPackage($name, $version)
{ {
$normVersion = self::$versionParser->normalize($version); $normVersion = self::$versionParser->normalize($version);

Loading…
Cancel
Save