Changed repository priority in the pool

main
Martin Hasoň 12 years ago
parent 5b42f99441
commit 2b08df5192

@ -53,7 +53,7 @@ class Pool
throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool."); throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
} }
return $priority; return -$priority;
} }
/** /**

@ -80,7 +80,7 @@ class DefaultPolicyTest extends TestCase
$this->assertEquals($expected, $selected); $this->assertEquals($expected, $selected);
} }
public function testSelectLastRepo() public function testSelectFirstRepo()
{ {
$this->repoImportant = new ArrayRepository; $this->repoImportant = new ArrayRepository;
@ -88,8 +88,8 @@ class DefaultPolicyTest extends TestCase
$this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', '1.0')); $this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repoInstalled); $this->pool->addRepository($this->repoInstalled);
$this->pool->addRepository($this->repo);
$this->pool->addRepository($this->repoImportant); $this->pool->addRepository($this->repoImportant);
$this->pool->addRepository($this->repo);
$literals = array(new Literal($packageA, true), new Literal($packageAImportant, true)); $literals = array(new Literal($packageA, true), new Literal($packageAImportant, true));
$expected = array(new Literal($packageAImportant, true)); $expected = array(new Literal($packageAImportant, true));

@ -54,7 +54,44 @@ class PoolTest extends TestCase
$secondPriority = $pool->getPriority($secondRepository); $secondPriority = $pool->getPriority($secondRepository);
$this->assertEquals(0, $firstPriority); $this->assertEquals(0, $firstPriority);
$this->assertEquals(1, $secondPriority); $this->assertEquals(-1, $secondPriority);
}
public function testWhatProvidesSamePackageForDifferentRepositories()
{
$pool = new Pool;
$firstRepository = new ArrayRepository;
$secondRepository = new ArrayRepository;
$firstPackage = $this->getPackage('foo', '1');
$secondPackage = $this->getPackage('foo', '1');
$thirdPackage = $this->getPackage('foo', '2');
$firstRepository->addPackage($firstPackage);
$secondRepository->addPackage($secondPackage);
$secondRepository->addPackage($thirdPackage);
$pool->addRepository($firstRepository);
$pool->addRepository($secondRepository);
$this->assertEquals(array($firstPackage, $secondPackage, $thirdPackage), $pool->whatProvides('foo'));
}
public function testWhatProvidesPackageWithConstraint()
{
$pool = new Pool;
$repository = new ArrayRepository;
$firstPackage = $this->getPackage('foo', '1');
$secondPackage = $this->getPackage('foo', '2');
$repository->addPackage($firstPackage);
$repository->addPackage($secondPackage);
$pool->addRepository($repository);
$this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
$this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2')));
} }
public function testPackageById() public function testPackageById()

@ -47,6 +47,32 @@ class RequestTest extends TestCase
$request->getJobs()); $request->getJobs());
} }
public function testRequestInstallSamePackageFromDifferentRepositories()
{
$pool = new Pool;
$repo1 = new ArrayRepository;
$repo2 = new ArrayRepository;
$foo1 = $this->getPackage('foo', '1');
$foo2 = $this->getPackage('foo', '1');
$repo1->addPackage($foo1);
$repo2->addPackage($foo2);
$pool->addRepository($repo1);
$pool->addRepository($repo2);
$request = new Request($pool);
$request->install('foo', $this->getVersionConstraint('=', '1'));
$this->assertEquals(
array(
array('packages' => array($foo1, $foo2), 'cmd' => 'install', 'packageName' => 'foo'),
),
$request->getJobs()
);
}
public function testUpdateAll() public function testUpdateAll()
{ {
$pool = new Pool; $pool = new Pool;

@ -9,7 +9,6 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Composer\Test\DependencyResolver; namespace Composer\Test\DependencyResolver;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
@ -70,6 +69,25 @@ class SolverTest extends TestCase
} }
} }
public function testSolverInstallSamePackageFromDifferentRepositories()
{
$repo1 = new ArrayRepository;
$repo2 = new ArrayRepository;
$repo1->addPackage($foo1 = $this->getPackage('foo', '1'));
$repo2->addPackage($foo2 = $this->getPackage('foo', '1'));
$this->pool->addRepository($this->repoInstalled);
$this->pool->addRepository($repo1);
$this->pool->addRepository($repo2);
$this->request->install('foo');
$this->checkSolverResult(array(
array('job' => 'install', 'package' => $foo1),
));
}
public function testSolverInstallWithDeps() public function testSolverInstallWithDeps()
{ {
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));

Loading…
Cancel
Save