Merge remote-tracking branch 'hason/priority'
Conflicts: src/Composer/Factory.phppull/454/merge
commit
3b77d25a3c
|
@ -53,7 +53,7 @@ class Pool
|
|||
throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
|
||||
}
|
||||
|
||||
return $priority;
|
||||
return -$priority;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -78,18 +78,7 @@ class Factory
|
|||
$rm = $this->createRepositoryManager($io);
|
||||
|
||||
// load default repository unless it's explicitly disabled
|
||||
$loadPackagist = true;
|
||||
if (isset($packageConfig['repositories'])) {
|
||||
foreach ($packageConfig['repositories'] as $repo) {
|
||||
if (isset($repo['packagist']) && $repo['packagist'] === false) {
|
||||
$loadPackagist = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($loadPackagist) {
|
||||
$this->addPackagistRepository($rm);
|
||||
}
|
||||
$packageConfig = $this->addPackagistRepository($packageConfig);
|
||||
|
||||
// load local repository
|
||||
$this->addLocalRepository($rm, $vendorDir);
|
||||
|
@ -145,9 +134,33 @@ class Factory
|
|||
$rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json')));
|
||||
}
|
||||
|
||||
protected function addPackagistRepository(RepositoryManager $rm)
|
||||
protected function addPackagistRepository(array $packageConfig)
|
||||
{
|
||||
$rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org')));
|
||||
$loadPackagist = true;
|
||||
$packagistConfig = array(
|
||||
'type' => 'composer',
|
||||
'url' => 'http://packagist.org'
|
||||
);
|
||||
if (isset($packageConfig['repositories'])) {
|
||||
foreach ($packageConfig['repositories'] as $key => $repo) {
|
||||
if (isset($repo['packagist'])) {
|
||||
if (true === $repo['packagist']) {
|
||||
$packageConfig['repositories'][$key] = $packagistConfig;
|
||||
}
|
||||
|
||||
$loadPackagist = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$packageConfig['repositories'] = array();
|
||||
}
|
||||
|
||||
if ($loadPackagist) {
|
||||
$packageConfig['repositories'][] = $packagistConfig;
|
||||
}
|
||||
|
||||
return $packageConfig;
|
||||
}
|
||||
|
||||
public function createDownloadManager(IOInterface $io)
|
||||
|
|
|
@ -80,7 +80,7 @@ class DefaultPolicyTest extends TestCase
|
|||
$this->assertEquals($expected, $selected);
|
||||
}
|
||||
|
||||
public function testSelectLastRepo()
|
||||
public function testSelectFirstRepo()
|
||||
{
|
||||
$this->repoImportant = new ArrayRepository;
|
||||
|
||||
|
@ -88,8 +88,8 @@ class DefaultPolicyTest extends TestCase
|
|||
$this->repoImportant->addPackage($packageAImportant = $this->getPackage('A', '1.0'));
|
||||
|
||||
$this->pool->addRepository($this->repoInstalled);
|
||||
$this->pool->addRepository($this->repo);
|
||||
$this->pool->addRepository($this->repoImportant);
|
||||
$this->pool->addRepository($this->repo);
|
||||
|
||||
$literals = array(new Literal($packageA, true), new Literal($packageAImportant, true));
|
||||
$expected = array(new Literal($packageAImportant, true));
|
||||
|
|
|
@ -54,7 +54,44 @@ class PoolTest extends TestCase
|
|||
$secondPriority = $pool->getPriority($secondRepository);
|
||||
|
||||
$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()
|
||||
|
|
|
@ -47,6 +47,32 @@ class RequestTest extends TestCase
|
|||
$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()
|
||||
{
|
||||
$pool = new Pool;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* 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;
|
||||
|
@ -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()
|
||||
{
|
||||
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?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;
|
||||
|
||||
use Composer\Factory;
|
||||
|
||||
class FactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider dataAddPackagistRepository
|
||||
*/
|
||||
public function testAddPackagistRepository($expected, $config)
|
||||
{
|
||||
$factory = new Factory();
|
||||
|
||||
$ref = new \ReflectionMethod($factory, 'addPackagistRepository');
|
||||
$ref->setAccessible(true);
|
||||
|
||||
$this->assertEquals($expected, $ref->invoke($factory, $config));
|
||||
}
|
||||
|
||||
public function dataAddPackagistRepository()
|
||||
{
|
||||
$f = function() {
|
||||
$repositories = func_get_args();
|
||||
return array('repositories' => $repositories);
|
||||
};
|
||||
|
||||
$data = array();
|
||||
$data[] = array(
|
||||
$f(array('type' => 'composer', 'url' => 'http://packagist.org')),
|
||||
$f()
|
||||
);
|
||||
|
||||
$data[] = array(
|
||||
$f(array('packagist' => false)),
|
||||
$f(array('packagist' => false))
|
||||
);
|
||||
|
||||
$data[] = array(
|
||||
$f(
|
||||
array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
|
||||
array('type' => 'composer', 'url' => 'http://packagist.org'),
|
||||
array('type' => 'pear', 'url' => 'http://pear.composer.org')
|
||||
),
|
||||
$f(
|
||||
array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
|
||||
array('packagist' => true),
|
||||
array('type' => 'pear', 'url' => 'http://pear.composer.org')
|
||||
)
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue