1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +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

@ -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());
}
}