2011-04-05 15:37:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-04-16 12:42:35 +00:00
|
|
|
* This file is part of Composer.
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
2011-04-16 12:42:35 +00:00
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\DependencyResolver;
|
|
|
|
|
2011-05-23 00:18:11 +00:00
|
|
|
use Composer\Repository\ArrayRepository;
|
2011-07-08 11:09:39 +00:00
|
|
|
use Composer\Repository\PlatformRepository;
|
2011-07-21 11:42:47 +00:00
|
|
|
use Composer\Repository\ComposerRepository;
|
2011-04-05 15:37:19 +00:00
|
|
|
use Composer\DependencyResolver\DefaultPolicy;
|
|
|
|
use Composer\DependencyResolver\Pool;
|
|
|
|
use Composer\DependencyResolver\Request;
|
|
|
|
use Composer\DependencyResolver\Solver;
|
2011-05-23 00:18:11 +00:00
|
|
|
use Composer\Package\MemoryPackage;
|
|
|
|
use Composer\Package\Link;
|
|
|
|
use Composer\Package\LinkConstraint\VersionConstraint;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
|
|
|
class SolverTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2011-08-05 08:08:21 +00:00
|
|
|
protected $pool;
|
|
|
|
protected $repo;
|
|
|
|
protected $repoInstalled;
|
|
|
|
protected $request;
|
|
|
|
protected $policy;
|
|
|
|
|
|
|
|
public function setUp()
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2011-08-05 08:08:21 +00:00
|
|
|
$this->pool = new Pool;
|
|
|
|
$this->repo = new ArrayRepository;
|
|
|
|
$this->repoInstalled = new ArrayRepository;
|
|
|
|
|
|
|
|
$this->request = new Request($this->pool);
|
|
|
|
$this->policy = new DefaultPolicy;
|
|
|
|
$this->solver = new Solver($this->policy, $this->pool, $this->repoInstalled);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverInstallSingle()
|
|
|
|
{
|
|
|
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->install('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array(
|
|
|
|
array('job' => 'install', 'package' => $packageA),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverInstallWithDeps()
|
|
|
|
{
|
|
|
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
|
|
|
|
$this->repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-05-23 00:18:11 +00:00
|
|
|
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-08-05 08:08:21 +00:00
|
|
|
$this->reposComplete();
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-08-05 08:08:21 +00:00
|
|
|
$this->request->install('A');
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-08-05 08:08:21 +00:00
|
|
|
$this->checkSolverResult(array(
|
|
|
|
array('job' => 'install', 'package' => $packageB),
|
|
|
|
array('job' => 'install', 'package' => $packageA),
|
|
|
|
));
|
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-08-05 08:08:21 +00:00
|
|
|
public function testSolverInstallInstalled()
|
|
|
|
{
|
|
|
|
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
|
|
|
|
$this->repoInstalled->addPackage(new MemoryPackage('A', '1.0'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->install('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverRemoveSingle()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-08-05 08:08:21 +00:00
|
|
|
$this->repoInstalled->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->remove('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array(
|
|
|
|
array('job' => 'remove', 'package' => $packageA),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverRemoveUninstalled()
|
|
|
|
{
|
|
|
|
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->remove('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverUpdateSingle()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
|
|
|
|
$this->repoInstalled->addPackage($packageA = new MemoryPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage($newPackageA = new MemoryPackage('A', '1.1'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->update('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array(
|
|
|
|
array('job' => 'update', 'package' => $newPackageA),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverUpdateCurrent()
|
|
|
|
{
|
|
|
|
$this->repoInstalled->addPackage(new MemoryPackage('A', '1.0'));
|
|
|
|
$this->repo->addPackage(new MemoryPackage('A', '1.0'));
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->update('A');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSolverFull()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete();
|
|
|
|
|
|
|
|
$this->repoInstalled->addPackage($packageD = new MemoryPackage('D', '1.0'));
|
|
|
|
$this->repoInstalled->addPackage($oldPackageC = new MemoryPackage('C', '1.0'));
|
|
|
|
|
|
|
|
$this->repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
|
|
|
|
$this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
|
|
|
|
$this->repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
|
|
|
|
$this->repo->addPackage($packageC = new MemoryPackage('C', '1.1'));
|
|
|
|
$this->repo->addPackage(new MemoryPackage('D', '1.0'));
|
|
|
|
$packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
|
|
|
|
|
|
|
|
$this->reposComplete();
|
|
|
|
|
|
|
|
$this->request->install('A');
|
|
|
|
$this->request->update('C');
|
|
|
|
$this->request->remove('D');
|
|
|
|
|
|
|
|
$this->checkSolverResult(array(
|
|
|
|
array('job' => 'install', 'package' => $packageB),
|
|
|
|
array('job' => 'install', 'package' => $packageA),
|
|
|
|
array('job' => 'remove', 'package' => $packageD),
|
|
|
|
array('job' => 'update', 'package' => $packageC),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function reposComplete()
|
|
|
|
{
|
|
|
|
$this->pool->addRepository($this->repoInstalled);
|
|
|
|
$this->pool->addRepository($this->repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function checkSolverResult(array $expected)
|
|
|
|
{
|
|
|
|
$result = $this->solver->solve($this->request);
|
2011-05-23 00:23:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|
2011-07-21 11:42:47 +00:00
|
|
|
|
|
|
|
public function testSolverWithComposerRepo()
|
|
|
|
{
|
|
|
|
$pool = new Pool;
|
|
|
|
$repoInstalled = new PlatformRepository;
|
|
|
|
$repo = new ComposerRepository('http://packagist.org');
|
|
|
|
list($monolog) = $repo->getPackages();
|
|
|
|
|
|
|
|
$pool->addRepository($repoInstalled);
|
|
|
|
$pool->addRepository($repo);
|
|
|
|
|
|
|
|
$request = new Request($pool);
|
|
|
|
|
|
|
|
$request->install('Monolog');
|
|
|
|
|
|
|
|
$policy = new DefaultPolicy;
|
|
|
|
$solver = new Solver($policy, $pool, $repoInstalled);
|
|
|
|
$result = $solver->solve($request);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'job' => 'install',
|
|
|
|
'package' => $monolog,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|