2013-11-22 10:10:54 +00:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
namespace Composer\Test\Repository;
|
2013-11-22 10:10:54 +00:00
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\RepositoryManager;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2016-01-26 13:32:04 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2013-11-22 10:10:54 +00:00
|
|
|
|
|
|
|
class RepositoryManagerTest extends TestCase
|
|
|
|
{
|
2016-01-26 13:32:04 +00:00
|
|
|
protected $tmpdir;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->tmpdir = $this->getUniqueTmpDirectory();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
if (is_dir($this->tmpdir)) {
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->removeDirectory($this->tmpdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 15:57:10 +00:00
|
|
|
public function testPrepend()
|
|
|
|
{
|
|
|
|
$rm = new RepositoryManager(
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
|
|
|
|
$this->getMockBuilder('Composer\Config')->getMock(),
|
2018-11-12 14:34:54 +00:00
|
|
|
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
|
|
|
|
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
|
2016-02-23 15:57:10 +00:00
|
|
|
);
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$repository1 = $this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock();
|
|
|
|
$repository2 = $this->getMockBuilder('Composer\Repository\RepositoryInterface')->getMock();
|
2016-02-23 15:57:10 +00:00
|
|
|
$rm->addRepository($repository1);
|
|
|
|
$rm->prependRepository($repository2);
|
|
|
|
|
|
|
|
$this->assertEquals(array($repository2, $repository1), $rm->getRepositories());
|
|
|
|
}
|
|
|
|
|
2013-11-22 10:10:54 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider creationCases
|
|
|
|
*/
|
2016-01-26 13:32:04 +00:00
|
|
|
public function testRepoCreation($type, $options, $exception = null)
|
2013-11-22 10:10:54 +00:00
|
|
|
{
|
2015-02-26 08:19:26 +00:00
|
|
|
if ($exception) {
|
|
|
|
$this->setExpectedException($exception);
|
|
|
|
}
|
2016-01-26 13:32:04 +00:00
|
|
|
|
2013-11-22 10:10:54 +00:00
|
|
|
$rm = new RepositoryManager(
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
|
|
|
|
$config = $this->getMockBuilder('Composer\Config')->setMethods(array('get'))->getMock(),
|
2018-11-12 14:34:54 +00:00
|
|
|
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
|
|
|
|
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
|
2013-11-22 10:10:54 +00:00
|
|
|
);
|
2016-01-26 13:32:04 +00:00
|
|
|
|
|
|
|
$tmpdir = $this->tmpdir;
|
|
|
|
$config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('get')
|
|
|
|
->will($this->returnCallback(function ($arg) use ($tmpdir) {
|
|
|
|
return 'cache-repo-dir' === $arg ? $tmpdir : null;
|
|
|
|
}))
|
|
|
|
;
|
|
|
|
|
2013-11-22 10:10:54 +00:00
|
|
|
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
|
|
|
|
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
|
|
|
|
$rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
|
|
|
|
$rm->setRepositoryClass('git', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('svn', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('perforce', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('hg', 'Composer\Repository\VcsRepository');
|
|
|
|
$rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository');
|
|
|
|
|
|
|
|
$rm->createRepository('composer', array('url' => 'http://example.org'));
|
2020-02-07 06:35:07 +00:00
|
|
|
$this->assertInstanceOf('Composer\Repository\RepositoryInterface', $rm->createRepository($type, $options));
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function creationCases()
|
|
|
|
{
|
2016-02-17 09:06:10 +00:00
|
|
|
$cases = array(
|
2013-11-22 10:10:54 +00:00
|
|
|
array('composer', array('url' => 'http://example.org')),
|
|
|
|
array('vcs', array('url' => 'http://github.com/foo/bar')),
|
|
|
|
array('git', array('url' => 'http://github.com/foo/bar')),
|
|
|
|
array('git', array('url' => 'git@example.org:foo/bar.git')),
|
|
|
|
array('svn', array('url' => 'svn://example.org/foo/bar')),
|
2021-08-18 12:25:35 +00:00
|
|
|
array('pear', array('url' => 'http://pear.example.org/foo'), 'InvalidArgumentException'),
|
2015-02-26 08:19:26 +00:00
|
|
|
array('package', array('package' => array())),
|
|
|
|
array('invalid', array(), 'InvalidArgumentException'),
|
2013-11-22 10:10:54 +00:00
|
|
|
);
|
2016-02-17 09:06:10 +00:00
|
|
|
|
|
|
|
if (class_exists('ZipArchive')) {
|
|
|
|
$cases[] = array('artifact', array('url' => '/path/to/zips'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cases;
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|
2020-04-09 11:39:06 +00:00
|
|
|
|
|
|
|
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');
|
2021-03-09 14:49:40 +00:00
|
|
|
/** @var \Composer\Repository\FilterRepository $repo */
|
2020-04-09 11:39:06 +00:00
|
|
|
$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());
|
|
|
|
}
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|