1
0
Fork 0

Adding tests for the default policy specifying its desired behaviour

pull/60/merge
Nils Adermann 2011-10-21 14:44:24 +02:00
parent 40cc5fea1d
commit e4c94dd415
4 changed files with 104 additions and 4 deletions

View File

@ -63,9 +63,8 @@ class DefaultPolicy implements PolicyInterface
return true; return true;
} }
public function selectPreferedPackages(Solver $solver, Pool $pool, RepositoryInterface $installed, array $literals) public function selectPreferedPackages(Pool $pool, RepositoryInterface $installed, array $literals)
{ {
// prefer installed, newest version, recommended, highest priority repository, ...
$newest = $this->selectNewestPackages($installed, $literals); $newest = $this->selectNewestPackages($installed, $literals);
$selected = array(); $selected = array();

View File

@ -25,5 +25,5 @@ interface PolicyInterface
function versionCompare(PackageInterface $a, PackageInterface $b, $operator); function versionCompare(PackageInterface $a, PackageInterface $b, $operator);
function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package, $allowAll); function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package, $allowAll);
function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package); function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, PackageInterface $package);
function selectPreferedPackages(Solver $solver, Pool $pool, RepositoryInterface $installed, array $literals); function selectPreferedPackages(Pool $pool, RepositoryInterface $installed, array $literals);
} }

View File

@ -1411,7 +1411,7 @@ class Solver
private function selectAndInstall($level, array $decisionQueue, $disableRules, Rule $rule) private function selectAndInstall($level, array $decisionQueue, $disableRules, Rule $rule)
{ {
// choose best package to install from decisionQueue // choose best package to install from decisionQueue
$literals = $this->policy->selectPreferedPackages($this, $this->pool, $this->installed, $decisionQueue); $literals = $this->policy->selectPreferedPackages($this->pool, $this->installed, $decisionQueue);
$selectedLiteral = array_shift($literals); $selectedLiteral = array_shift($literals);

View File

@ -0,0 +1,101 @@
<?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\Repository\ArrayRepository;
use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Literal;
use Composer\Package\MemoryPackage;
use Composer\Package\Link;
use Composer\Package\LinkConstraint\VersionConstraint;
class DefaultPolicyTest extends \PHPUnit_Framework_TestCase
{
protected $pool;
protected $repo;
protected $repoInstalled;
protected $request;
protected $policy;
public function setUp()
{
$this->pool = new Pool;
$this->repo = new ArrayRepository;
$this->repoInstalled = new ArrayRepository;
$this->policy = new DefaultPolicy;
}
public function testSelectSingle()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->pool->addRepository($this->repo);
$literals = array(new Literal($packageA, true));
$expected = array(new Literal($packageA, true));
$selected = $this->policy->selectPreferedPackages($this->pool, $this->repoInstalled, $literals);
$this->assertEquals($expected, $selected);
}
public function testSelectNewest()
{
$this->repo->addPackage($packageA1 = new MemoryPackage('A', '1.0'));
$this->repo->addPackage($packageA2 = new MemoryPackage('A', '2.0'));
$this->pool->addRepository($this->repo);
$literals = array(new Literal($packageA1, true), new Literal($packageA2, true));
$expected = array(new Literal($packageA2, true));
$selected = $this->policy->selectPreferedPackages($this->pool, $this->repoInstalled, $literals);
$this->assertEquals($expected, $selected);
}
public function testSelectInstalled()
{
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repoInstalled->addPackage($packageAInstalled = new MemoryPackage('A', '1.0'));
$this->pool->addRepository($this->repo);
$this->pool->addRepository($this->repoInstalled);
$literals = array(new Literal($packageA, true), new Literal($packageAInstalled, true));
$expected = array(new Literal($packageAInstalled, true));
$selected = $this->policy->selectPreferedPackages($this->pool, $this->repoInstalled, $literals);
$this->assertEquals($expected, $selected);
}
public function testSelectLastRepo()
{
$this->markTestIncomplete();
$this->repoImportant = new ArrayRepository;
$this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
$this->repoImportant->addPackage($packageAImportant = new MemoryPackage('A', '1.0'));
$this->pool->addRepository($this->repo);
$this->pool->addRepository($this->repoImportant);
$literals = array(new Literal($packageA, true), new Literal($packageAImportant, true));
$expected = array(new Literal($packageAImportant, true));
$selected = $this->policy->selectPreferedPackages($this->pool, $this->repoInstalled, $literals);
$this->assertEquals($expected, $selected);
}
}