1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 09:02:59 +00:00

Add options to configure repository priorities

This commit is contained in:
Jordi Boggiano 2020-04-09 13:39:06 +02:00
parent 59c831c2f8
commit b6bad4eef6
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
11 changed files with 455 additions and 5 deletions

View file

@ -28,7 +28,7 @@ Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires foo/a 2.*, it is satisfiable by foo/a[2.0.0] from package repo (defining 1 package) but foo/a[1.0.0] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable.
- Root composer.json requires foo/a 2.*, it is satisfiable by foo/a[2.0.0] from package repo (defining 1 package) but foo/a[1.0.0] from package repo (defining 1 package) has higher repository priority. The packages with higher priority do not match your constraint and are therefore not installable. See https://getcomposer.org/repoprio for details and assistance.
--EXPECT--
--EXPECT-EXIT-CODE--

View file

@ -0,0 +1,49 @@
--TEST--
Test that filter repositories apply correctly
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "foo/a", "version": "1.0.0" }
],
"canonical": false
},
{
"type": "package",
"package": [
{ "name": "foo/a", "version": "1.0.0" },
{ "name": "foo/b", "version": "1.0.0" }
],
"only": ["foo/b"]
},
{
"type": "package",
"package": [
{ "name": "foo/a", "version": "1.2.0" },
{ "name": "foo/c", "version": "1.2.0" }
],
"exclude": ["foo/c"]
},
{
"type": "package",
"package": [
{ "name": "foo/a", "version": "1.1.0" },
{ "name": "foo/b", "version": "1.1.0" },
{ "name": "foo/c", "version": "1.1.0" }
]
}
],
"require": {
"foo/a": "1.*",
"foo/b": "1.*",
"foo/c": "1.*"
}
}
--RUN--
update
--EXPECT--
Installing foo/a (1.2.0)
Installing foo/b (1.0.0)
Installing foo/c (1.1.0)

View file

@ -0,0 +1,69 @@
<?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\Repository;
use Composer\Test\TestCase;
use Composer\Repository\FilterRepository;
use Composer\Repository\ArrayRepository;
use Composer\Semver\Constraint\EmptyConstraint;
use Composer\Package\BasePackage;
class FilterRepositoryTest extends TestCase
{
private $arrayRepo;
public function setUp()
{
$this->arrayRepo = new ArrayRepository();
$this->arrayRepo->addPackage($this->getPackage('foo/aaa', '1.0.0'));
$this->arrayRepo->addPackage($this->getPackage('foo/bbb', '1.0.0'));
$this->arrayRepo->addPackage($this->getPackage('bar/xxx', '1.0.0'));
$this->arrayRepo->addPackage($this->getPackage('baz/yyy', '1.0.0'));
}
/**
* @dataProvider repoMatchingTests
*/
public function testRepoMatching($expected, $config)
{
$repo = new FilterRepository($this->arrayRepo, $config);
$packages = $repo->getPackages();
$this->assertSame($expected, array_map(function ($p) { return $p->getName(); }, $packages));
}
public static function repoMatchingTests()
{
return array(
array(array('foo/aaa', 'foo/bbb'), array('only' => array('foo/*'))),
array(array('foo/aaa', 'baz/yyy'), array('only' => array('foo/aaa', 'baz/yyy'))),
array(array('bar/xxx'), array('exclude' => array('foo/*', 'baz/yyy'))),
);
}
public function testCanonicalDefaultTrue()
{
$repo = new FilterRepository($this->arrayRepo, array());
$result = $repo->loadPackages(array('foo/aaa' => new EmptyConstraint), BasePackage::$stabilities, array());
$this->assertCount(1, $result['packages']);
$this->assertCount(1, $result['namesFound']);
}
public function testNonCanonical()
{
$repo = new FilterRepository($this->arrayRepo, array('canonical' => false));
$result = $repo->loadPackages(array('foo/aaa' => new EmptyConstraint), BasePackage::$stabilities, array());
$this->assertCount(1, $result['packages']);
$this->assertCount(0, $result['namesFound']);
}
}

View file

@ -108,4 +108,20 @@ class RepositoryManagerTest extends TestCase
return $cases;
}
public function testFilterRepoWrapping()
{
$rm = new RepositoryManager(
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$config = $this->getMockBuilder('Composer\Config')->setMethods(array('get'))->getMock(),
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
);
$rm->setRepositoryClass('path', 'Composer\Repository\PathRepository');
$repo = $rm->createRepository('path', array('type' => 'path', 'url' => __DIR__, 'only' => array('foo/bar')));
$this->assertInstanceOf('Composer\Repository\FilterRepository', $repo);
$this->assertInstanceOf('Composer\Repository\PathRepository', $repo->getRepository());
}
}