123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923 |
- <?php
- /*
- * This file is part of Composer.
- *
- * (c) Nils Adermann <naderman@naderman.de>
- * Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Composer\Test\DependencyResolver;
- use Composer\IO\NullIO;
- use Composer\Repository\ArrayRepository;
- use Composer\Repository\LockArrayRepository;
- use Composer\DependencyResolver\DefaultPolicy;
- use Composer\DependencyResolver\Pool;
- use Composer\DependencyResolver\Request;
- use Composer\DependencyResolver\Solver;
- use Composer\DependencyResolver\SolverProblemsException;
- use Composer\Package\Link;
- use Composer\Repository\InstalledArrayRepository;
- use Composer\Repository\RepositorySet;
- use Composer\Test\TestCase;
- use Composer\Semver\Constraint\MultiConstraint;
- use Composer\Semver\Constraint\EmptyConstraint;
- class SolverTest extends TestCase
- {
- protected $repoSet;
- protected $repo;
- protected $repoLocked;
- protected $request;
- protected $policy;
- protected $solver;
- protected $pool;
- public function setUp()
- {
- $this->repoSet = new RepositorySet();
- $this->repo = new ArrayRepository;
- $this->repoLocked = new LockArrayRepository;
- $this->request = new Request($this->repoLocked);
- $this->policy = new DefaultPolicy;
- }
- public function testSolverInstallSingle()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testSolverRemoveIfNotRequested()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->checkSolverResult(array(
- array('job' => 'remove', 'package' => $packageA),
- ));
- }
- public function testInstallNonExistingPackageFails()
- {
- $this->repo->addPackage($this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->requireName('B', $this->getVersionConstraint('==', '1'));
- $this->createSolver();
- try {
- $transaction = $this->solver->solve($this->request);
- $this->fail('Unsolvable conflict did not result in exception.');
- } catch (SolverProblemsException $e) {
- $problems = $e->getProblems();
- $this->assertCount(1, $problems);
- $this->assertEquals(2, $e->getCode());
- $this->assertEquals("\n - Root composer.json requires b, it could not be found in any version, there may be a typo in the package name.", $problems[0]->getPrettyString($this->repoSet, $this->request, $this->pool, false));
- }
- }
- public function testSolverInstallSamePackageFromDifferentRepositories()
- {
- $repo1 = new ArrayRepository;
- $repo2 = new ArrayRepository;
- $repo1->addPackage($foo1 = $this->getPackage('foo', '1'));
- $repo2->addPackage($foo2 = $this->getPackage('foo', '1'));
- $this->repoSet->addRepository($repo1);
- $this->repoSet->addRepository($repo2);
- $this->request->requireName('foo');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $foo1),
- ));
- }
- public function testSolverInstallWithDeps()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testSolverInstallHonoursNotEqualOperator()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageB11 = $this->getPackage('B', '1.1'));
- $this->repo->addPackage($newPackageB12 = $this->getPackage('B', '1.2'));
- $this->repo->addPackage($newPackageB13 = $this->getPackage('B', '1.3'));
- $packageA->setRequires(array(
- 'b' => new Link('A', 'B', new MultiConstraint(array(
- $this->getVersionConstraint('<=', '1.3'),
- $this->getVersionConstraint('<>', '1.3'),
- $this->getVersionConstraint('!=', '1.2'),
- )), 'requires'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $newPackageB11),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testSolverInstallWithDepsInOrder()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
- $packageB->setRequires(array(
- 'a' => new Link('B', 'A', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- 'c' => new Link('B', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageC->setRequires(array(
- 'a' => new Link('C', 'A', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('B');
- $this->request->requireName('C');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageA),
- array('job' => 'install', 'package' => $packageC),
- array('job' => 'install', 'package' => $packageB),
- ));
- }
- public function testSolverFixLocked()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->fixPackage($packageA);
- $this->checkSolverResult(array());
- }
- public function testSolverFixLockedWithAlternative()
- {
- $this->repo->addPackage($this->getPackage('A', '1.0'));
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->fixPackage($packageA);
- $this->checkSolverResult(array());
- }
- public function testSolverUpdateDoesOnlyUpdate()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repoLocked->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
- $this->reposComplete();
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0.0.0'), 'requires')));
- $this->request->fixPackage($packageA);
- $this->request->requireName('B', $this->getVersionConstraint('=', '1.1.0.0'));
- $this->checkSolverResult(array(
- array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
- ));
- }
- public function testSolverUpdateSingle()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
- ));
- }
- public function testSolverUpdateAll()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repoLocked->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
- $packageA->setRequires(array('b' => new Link('A', 'B', null, 'requires')));
- $newPackageA->setRequires(array('b' => new Link('A', 'B', null, 'requires')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
- array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
- ));
- }
- public function testSolverUpdateCurrent()
- {
- $this->repoLocked->addPackage($this->getPackage('A', '1.0'));
- $this->repo->addPackage($this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array());
- }
- public function testSolverUpdateOnlyUpdatesSelectedPackage()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repoLocked->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageAnewer = $this->getPackage('A', '1.1'));
- $this->repo->addPackage($packageBnewer = $this->getPackage('B', '1.1'));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->fixPackage($packageB);
- $this->checkSolverResult(array(
- array('job' => 'update', 'from' => $packageA, 'to' => $packageAnewer),
- ));
- }
- public function testSolverUpdateConstrained()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
- $this->repo->addPackage($this->getPackage('A', '2.0'));
- $this->reposComplete();
- $this->request->requireName('A', $this->getVersionConstraint('<', '2.0.0.0'));
- $this->checkSolverResult(array(array(
- 'job' => 'update',
- 'from' => $packageA,
- 'to' => $newPackageA,
- )));
- }
- public function testSolverUpdateFullyConstrained()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
- $this->repo->addPackage($this->getPackage('A', '2.0'));
- $this->reposComplete();
- $this->request->requireName('A', $this->getVersionConstraint('<', '2.0.0.0'));
- $this->checkSolverResult(array(array(
- 'job' => 'update',
- 'from' => $packageA,
- 'to' => $newPackageA,
- )));
- }
- public function testSolverUpdateFullyConstrainedPrunesInstalledPackages()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repoLocked->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2'));
- $this->repo->addPackage($this->getPackage('A', '2.0'));
- $this->reposComplete();
- $this->request->requireName('A', $this->getVersionConstraint('<', '2.0.0.0'));
- $this->checkSolverResult(array(
- array(
- 'job' => 'remove',
- 'package' => $packageB,
- ),
- array(
- 'job' => 'update',
- 'from' => $packageA,
- 'to' => $newPackageA,
- ),
- ));
- }
- public function testSolverAllJobs()
- {
- $this->repoLocked->addPackage($packageD = $this->getPackage('D', '1.0'));
- $this->repoLocked->addPackage($oldPackageC = $this->getPackage('C', '1.0'));
- $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
- $this->repo->addPackage($packageC = $this->getPackage('C', '1.1'));
- $this->repo->addPackage($this->getPackage('D', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('C');
- $this->checkSolverResult(array(
- array('job' => 'remove', 'package' => $packageD),
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA),
- array('job' => 'update', 'from' => $oldPackageC, 'to' => $packageC),
- ));
- }
- public function testSolverThreeAlternativeRequireAndConflict()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
- $this->repo->addPackage($middlePackageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
- $this->repo->addPackage($oldPackageB = $this->getPackage('B', '0.9'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('<', '1.1'), 'requires')));
- $packageA->setConflicts(array('b' => new Link('A', 'B', $this->getVersionConstraint('<', '1.0'), 'conflicts')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $middlePackageB),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testSolverObsolete()
- {
- $this->repoLocked->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageB->setReplaces(array('a' => new Link('B', 'A', new EmptyConstraint())));
- $this->reposComplete();
- $this->request->requireName('B');
- $this->checkSolverResult(array(
- array('job' => 'remove', 'package' => $packageA),
- array('job' => 'install', 'package' => $packageB),
- ));
- }
- public function testInstallOneOfTwoAlternatives()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('A', '1.0'));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testInstallProvider()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageQ->setProvides(array('b' => new Link('Q', 'B', $this->getVersionConstraint('=', '1.0'), 'provides')));
- $this->reposComplete();
- $this->request->requireName('A');
- // must explicitly pick the provider, so error in this case
- $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
- $this->createSolver();
- $this->solver->solve($this->request);
- }
- public function testSkipReplacerOfExistingPackage()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageQ->setReplaces(array('b' => new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testNoInstallReplacerOfMissingPackage()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageQ->setReplaces(array('b' => new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
- $this->createSolver();
- $this->solver->solve($this->request);
- }
- public function testSkipReplacedPackageIfReplacerIsSelected()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageQ = $this->getPackage('Q', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageQ->setReplaces(array('b' => new Link('Q', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('Q');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageQ),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testPickOlderIfNewerConflicts()
- {
- $this->repo->addPackage($packageX = $this->getPackage('X', '1.0'));
- $packageX->setRequires(array(
- 'a' => new Link('X', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires'),
- 'b' => new Link('X', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'requires'),
- ));
- $this->repo->addPackage($packageA = $this->getPackage('A', '2.0.0'));
- $this->repo->addPackage($newPackageA = $this->getPackage('A', '2.1.0'));
- $this->repo->addPackage($newPackageB = $this->getPackage('B', '2.1.0'));
- $packageA->setRequires(array('b' => 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 is not installable
- $newPackageA->setRequires(array('b' => 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
- // but an alternative option for A and B both exists
- // this creates a more difficult so solve conflict
- $this->repo->addPackage($packageS = $this->getPackage('S', '2.0.0'));
- $packageS->setReplaces(array(
- 'a' => new Link('S', 'A', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces'),
- 'b' => new Link('S', 'B', $this->getVersionConstraint('>=', '2.0.0.0'), 'replaces'),
- ));
- $this->reposComplete();
- $this->request->requireName('X');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $newPackageB),
- array('job' => 'install', 'package' => $packageA),
- array('job' => 'install', 'package' => $packageX),
- ));
- }
- public function testInstallCircularRequire()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB1 = $this->getPackage('B', '0.9'));
- $this->repo->addPackage($packageB2 = $this->getPackage('B', '1.1'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageB2->setRequires(array('a' => new Link('B', 'A', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageB2),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testInstallAlternativeWithCircularRequire()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
- $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
- $packageA->setRequires(array('b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageB->setRequires(array('virtual' => new Link('B', 'Virtual', $this->getVersionConstraint('>=', '1.0'), 'requires')));
- $packageC->setProvides(array('virtual' => new Link('C', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
- $packageD->setProvides(array('virtual' => new Link('D', 'Virtual', $this->getVersionConstraint('==', '1.0'), 'provides')));
- $packageC->setRequires(array('a' => new Link('C', 'A', $this->getVersionConstraint('==', '1.0'), 'requires')));
- $packageD->setRequires(array('a' => new Link('D', 'A', $this->getVersionConstraint('==', '1.0'), 'requires')));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('C');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA),
- array('job' => 'install', 'package' => $packageC),
- ));
- }
- /**
- * If a replacer D replaces B and C with C not otherwise available,
- * D must be installed instead of the original B.
- */
- public function testUseReplacerIfNecessary()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
- $this->repo->addPackage($packageD2 = $this->getPackage('D', '1.1'));
- $packageA->setRequires(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- 'c' => new Link('A', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageD->setReplaces(array(
- 'b' => new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
- 'c' => new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
- ));
- $packageD2->setReplaces(array(
- 'b' => new Link('D', 'B', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
- 'c' => new Link('D', 'C', $this->getVersionConstraint('>=', '1.0'), 'replaces'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('D');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageD2),
- array('job' => 'install', 'package' => $packageA),
- ));
- }
- public function testIssue265()
- {
- $this->repo->addPackage($packageA1 = $this->getPackage('A', '2.0.999999-dev'));
- $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.1-dev'));
- $this->repo->addPackage($packageA3 = $this->getPackage('A', '2.2-dev'));
- $this->repo->addPackage($packageB1 = $this->getPackage('B', '2.0.10'));
- $this->repo->addPackage($packageB2 = $this->getPackage('B', '2.0.9'));
- $this->repo->addPackage($packageC = $this->getPackage('C', '2.0-dev'));
- $this->repo->addPackage($packageD = $this->getPackage('D', '2.0.9'));
- $packageC->setRequires(array(
- 'a' => new Link('C', 'A', $this->getVersionConstraint('>=', '2.0'), 'requires'),
- 'd' => new Link('C', 'D', $this->getVersionConstraint('>=', '2.0'), 'requires'),
- ));
- $packageD->setRequires(array(
- 'a' => new Link('D', 'A', $this->getVersionConstraint('>=', '2.1'), 'requires'),
- 'b' => new Link('D', 'B', $this->getVersionConstraint('>=', '2.0-dev'), 'requires'),
- ));
- $packageB1->setRequires(array('a' => new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
- $packageB2->setRequires(array('a' => new Link('B', 'A', $this->getVersionConstraint('==', '2.1.0.0-dev'), 'requires')));
- $packageB2->setReplaces(array('d' => new Link('B', 'D', $this->getVersionConstraint('==', '2.0.9.0'), 'replaces')));
- $this->reposComplete();
- $this->request->requireName('C', $this->getVersionConstraint('==', '2.0.0.0-dev'));
- $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
- $this->createSolver();
- $this->solver->solve($this->request);
- }
- public function testConflictResultEmpty()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageA->setConflicts(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'conflicts'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->request->requireName('B');
- $this->createSolver();
- try {
- $transaction = $this->solver->solve($this->request);
- $this->fail('Unsolvable conflict did not result in exception.');
- } catch (SolverProblemsException $e) {
- $problems = $e->getProblems();
- $this->assertCount(1, $problems);
- $msg = "\n";
- $msg .= " Problem 1\n";
- $msg .= " - Root composer.json requires a -> satisfiable by A[1.0].\n";
- $msg .= " - A 1.0 conflicts with B 1.0.\n";
- $msg .= " - Root composer.json requires b -> satisfiable by B[1.0].\n";
- $this->assertEquals($msg, $e->getPrettyString($this->repoSet, $this->request, $this->pool, false));
- }
- }
- public function testUnsatisfiableRequires()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageA->setRequires(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('>=', '2.0'), 'requires'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->createSolver();
- try {
- $transaction = $this->solver->solve($this->request);
- $this->fail('Unsolvable conflict did not result in exception.');
- } catch (SolverProblemsException $e) {
- $problems = $e->getProblems();
- $this->assertCount(1, $problems);
- // TODO assert problem properties
- $msg = "\n";
- $msg .= " Problem 1\n";
- $msg .= " - Root composer.json requires a -> satisfiable by A[1.0].\n";
- $msg .= " - A 1.0 requires b >= 2.0 -> found B[1.0] but it does not match the constraint.\n";
- $this->assertEquals($msg, $e->getPrettyString($this->repoSet, $this->request, $this->pool, false));
- }
- }
- public function testRequireMismatchException()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageB2 = $this->getPackage('B', '0.9'));
- $this->repo->addPackage($packageC = $this->getPackage('C', '1.0'));
- $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
- $packageA->setRequires(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageB->setRequires(array(
- 'c' => new Link('B', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageC->setRequires(array(
- 'd' => new Link('C', 'D', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageD->setRequires(array(
- 'b' => new Link('D', 'B', $this->getVersionConstraint('<', '1.0'), 'requires'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->createSolver();
- try {
- $transaction = $this->solver->solve($this->request);
- $this->fail('Unsolvable conflict did not result in exception.');
- } catch (SolverProblemsException $e) {
- $problems = $e->getProblems();
- $this->assertCount(1, $problems);
- $msg = "\n";
- $msg .= " Problem 1\n";
- $msg .= " - C 1.0 requires d >= 1.0 -> satisfiable by D[1.0].\n";
- $msg .= " - D 1.0 requires b < 1.0 -> satisfiable by B[0.9].\n";
- $msg .= " - B 1.0 requires c >= 1.0 -> satisfiable by C[1.0].\n";
- $msg .= " - You can only install one version of a package, so only one of these can be installed: B[0.9, 1.0].\n";
- $msg .= " - A 1.0 requires b >= 1.0 -> satisfiable by B[1.0].\n";
- $msg .= " - Root composer.json requires a -> satisfiable by A[1.0].\n";
- $this->assertEquals($msg, $e->getPrettyString($this->repoSet, $this->request, $this->pool, false));
- }
- }
- public function testLearnLiteralsWithSortedRuleLiterals()
- {
- $this->repo->addPackage($packageTwig2 = $this->getPackage('twig/twig', '2.0'));
- $this->repo->addPackage($packageTwig16 = $this->getPackage('twig/twig', '1.6'));
- $this->repo->addPackage($packageTwig15 = $this->getPackage('twig/twig', '1.5'));
- $this->repo->addPackage($packageSymfony = $this->getPackage('symfony/symfony', '2.0'));
- $this->repo->addPackage($packageTwigBridge = $this->getPackage('symfony/twig-bridge', '2.0'));
- $packageTwigBridge->setRequires(array(
- 'twig/twig' => new Link('symfony/twig-bridge', 'twig/twig', $this->getVersionConstraint('<', '2.0'), 'requires'),
- ));
- $packageSymfony->setReplaces(array(
- 'symfony/twig-bridge' => new Link('symfony/symfony', 'symfony/twig-bridge', $this->getVersionConstraint('==', '2.0'), 'replaces'),
- ));
- $this->reposComplete();
- $this->request->requireName('symfony/twig-bridge');
- $this->request->requireName('twig/twig');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageTwig16),
- array('job' => 'install', 'package' => $packageTwigBridge),
- ));
- }
- public function testInstallRecursiveAliasDependencies()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '2.0'));
- $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0'));
- $packageA2->setRequires(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('==', '2.0'), 'requires', '== 2.0'),
- ));
- $packageB->setRequires(array(
- 'a' => new Link('B', 'A', $this->getVersionConstraint('>=', '2.0'), 'requires'),
- ));
- $this->repo->addPackage($packageA2Alias = $this->getAliasPackage($packageA2, '1.1'));
- $this->reposComplete();
- $this->request->requireName('A', $this->getVersionConstraint('==', '1.1.0.0'));
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA2),
- array('job' => 'install', 'package' => $packageA2Alias),
- ));
- }
- public function testInstallDevAlias()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $packageB->setRequires(array(
- 'a' => new Link('B', 'A', $this->getVersionConstraint('<', '2.0'), 'requires'),
- ));
- $this->repo->addPackage($packageAAlias = $this->getAliasPackage($packageA, '1.1'));
- $this->reposComplete();
- $this->request->requireName('A', $this->getVersionConstraint('==', '2.0'));
- $this->request->requireName('B');
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageA),
- array('job' => 'install', 'package' => $packageAAlias),
- array('job' => 'install', 'package' => $packageB),
- ));
- }
- /**
- * Tests for a bug introduced in commit 451bab1c2cd58e05af6e21639b829408ad023463 Solver.php line 554/523
- *
- * Every package and link in this test matters, only a combination this complex will run into the situation in which
- * a negatively decided literal will need to be learned inverted as a positive assertion.
- *
- * In particular in this case the goal is to first have the solver decide X 2.0 should not be installed to later
- * decide to learn that X 2.0 must be installed and revert decisions to retry solving with this new assumption.
- */
- public function testLearnPositiveLiteral()
- {
- $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
- $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
- $this->repo->addPackage($packageC1 = $this->getPackage('C', '1.0'));
- $this->repo->addPackage($packageC2 = $this->getPackage('C', '2.0'));
- $this->repo->addPackage($packageD = $this->getPackage('D', '1.0'));
- $this->repo->addPackage($packageE = $this->getPackage('E', '1.0'));
- $this->repo->addPackage($packageF1 = $this->getPackage('F', '1.0'));
- $this->repo->addPackage($packageF2 = $this->getPackage('F', '2.0'));
- $this->repo->addPackage($packageG1 = $this->getPackage('G', '1.0'));
- $this->repo->addPackage($packageG2 = $this->getPackage('G', '2.0'));
- $this->repo->addPackage($packageG3 = $this->getPackage('G', '3.0'));
- $packageA->setRequires(array(
- 'b' => new Link('A', 'B', $this->getVersionConstraint('==', '1.0'), 'requires'),
- 'c' => new Link('A', 'C', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- 'd' => new Link('A', 'D', $this->getVersionConstraint('==', '1.0'), 'requires'),
- ));
- $packageB->setRequires(array(
- 'e' => new Link('B', 'E', $this->getVersionConstraint('==', '1.0'), 'requires'),
- ));
- $packageC1->setRequires(array(
- 'f' => new Link('C', 'F', $this->getVersionConstraint('==', '1.0'), 'requires'),
- ));
- $packageC2->setRequires(array(
- 'f' => new Link('C', 'F', $this->getVersionConstraint('==', '1.0'), 'requires'),
- 'g' => new Link('C', 'G', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageD->setRequires(array(
- 'f' => new Link('D', 'F', $this->getVersionConstraint('>=', '1.0'), 'requires'),
- ));
- $packageE->setRequires(array(
- 'g' => new Link('E', 'G', $this->getVersionConstraint('<=', '2.0'), 'requires'),
- ));
- $this->reposComplete();
- $this->request->requireName('A');
- $this->createSolver();
- // check correct setup for assertion later
- $this->assertFalse($this->solver->testFlagLearnedPositiveLiteral);
- $this->checkSolverResult(array(
- array('job' => 'install', 'package' => $packageF1),
- array('job' => 'install', 'package' => $packageD),
- array('job' => 'install', 'package' => $packageG2),
- array('job' => 'install', 'package' => $packageC2),
- array('job' => 'install', 'package' => $packageE),
- array('job' => 'install', 'package' => $packageB),
- array('job' => 'install', 'package' => $packageA),
- ));
- // verify that the code path leading to a negative literal resulting in a positive learned literal is actually
- // executed
- $this->assertTrue($this->solver->testFlagLearnedPositiveLiteral);
- }
- protected function reposComplete()
- {
- $this->repoSet->addRepository($this->repo);
- $this->repoSet->addRepository($this->repoLocked);
- }
- protected function createSolver()
- {
- $io = new NullIO();
- $this->pool = $this->repoSet->createPool($this->request, $io);
- $this->solver = new Solver($this->policy, $this->pool, $io);
- }
- protected function checkSolverResult(array $expected)
- {
- $this->createSolver();
- $transaction = $this->solver->solve($this->request);
- $result = array();
- foreach ($transaction->getOperations() as $operation) {
- if ('update' === $operation->getOperationType()) {
- $result[] = array(
- 'job' => 'update',
- 'from' => $operation->getInitialPackage(),
- 'to' => $operation->getTargetPackage(),
- );
- } else {
- $job = ('uninstall' === $operation->getOperationType() ? 'remove' : 'install');
- $result[] = array(
- 'job' => $job,
- 'package' => $operation->getPackage(),
- );
- }
- }
- $this->assertEquals($expected, $result);
- }
- }
|