2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2013-11-22 10:10:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2022-02-22 15:47:09 +00:00
|
|
|
use Composer\Config;
|
2013-11-22 10:10:54 +00:00
|
|
|
|
|
|
|
class RepositoryManagerTest extends TestCase
|
|
|
|
{
|
2021-10-27 13:29:52 +00:00
|
|
|
/** @var string */
|
2016-01-26 13:32:04 +00:00
|
|
|
protected $tmpdir;
|
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2016-01-26 13:32:04 +00:00
|
|
|
{
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->tmpdir = self::getUniqueTmpDirectory();
|
2016-01-26 13:32:04 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:07 +00:00
|
|
|
protected function tearDown(): void
|
2016-01-26 13:32:04 +00:00
|
|
|
{
|
2021-12-09 16:09:07 +00:00
|
|
|
parent::tearDown();
|
2016-01-26 13:32:04 +00:00
|
|
|
if (is_dir($this->tmpdir)) {
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->removeDirectory($this->tmpdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testPrepend(): void
|
2016-02-23 15:57:10 +00:00
|
|
|
{
|
|
|
|
$rm = new RepositoryManager(
|
2018-04-12 08:24:56 +00:00
|
|
|
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
|
2022-02-22 15:47:09 +00:00
|
|
|
new Config,
|
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);
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$this->assertEquals([$repository2, $repository1], $rm->getRepositories());
|
2016-02-23 15:57:10 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 10:10:54 +00:00
|
|
|
/**
|
2021-10-27 13:29:52 +00:00
|
|
|
* @dataProvider provideRepoCreationTestCases
|
|
|
|
*
|
|
|
|
* @param array<string, mixed> $options
|
2021-12-09 19:55:26 +00:00
|
|
|
* @param class-string<\Throwable>|null $exception
|
2013-11-22 10:10:54 +00:00
|
|
|
*/
|
2022-02-22 15:47:09 +00:00
|
|
|
public function testRepoCreation(string $type, array $options, ?string $exception = null): void
|
2013-11-22 10:10:54 +00:00
|
|
|
{
|
2021-12-09 21:14:04 +00:00
|
|
|
if ($exception !== null) {
|
2021-12-09 19:55:26 +00:00
|
|
|
self::expectException($exception);
|
2015-02-26 08:19:26 +00:00
|
|
|
}
|
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(),
|
2022-02-22 15:47:09 +00:00
|
|
|
$config = new Config,
|
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;
|
2022-02-22 15:47:09 +00:00
|
|
|
$config->merge(['config' => ['cache-repo-dir' => $tmpdir]]);
|
2016-01-26 13:32:04 +00:00
|
|
|
|
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');
|
|
|
|
|
2022-08-17 12:20:07 +00:00
|
|
|
$rm->createRepository('composer', ['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
|
|
|
}
|
|
|
|
|
2022-02-21 12:42:28 +00:00
|
|
|
public function provideRepoCreationTestCases(): array
|
2013-11-22 10:10:54 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$cases = [
|
|
|
|
['composer', ['url' => 'http://example.org']],
|
|
|
|
['vcs', ['url' => 'http://github.com/foo/bar']],
|
|
|
|
['git', ['url' => 'http://github.com/foo/bar']],
|
|
|
|
['git', ['url' => 'git@example.org:foo/bar.git']],
|
|
|
|
['svn', ['url' => 'svn://example.org/foo/bar']],
|
|
|
|
['pear', ['url' => 'http://pear.example.org/foo'], 'InvalidArgumentException'],
|
|
|
|
['package', ['package' => []]],
|
|
|
|
['invalid', [], 'InvalidArgumentException'],
|
|
|
|
];
|
2016-02-17 09:06:10 +00:00
|
|
|
|
|
|
|
if (class_exists('ZipArchive')) {
|
2022-08-17 12:20:07 +00:00
|
|
|
$cases[] = ['artifact', ['url' => '/path/to/zips']];
|
2016-02-17 09:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $cases;
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|
2020-04-09 11:39:06 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFilterRepoWrapping(): void
|
2020-04-09 11:39:06 +00:00
|
|
|
{
|
|
|
|
$rm = new RepositoryManager(
|
|
|
|
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
|
2022-08-17 12:20:07 +00:00
|
|
|
$config = $this->getMockBuilder('Composer\Config')->onlyMethods(['get'])->getMock(),
|
2020-04-09 11:39:06 +00:00
|
|
|
$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 */
|
2022-08-17 12:20:07 +00:00
|
|
|
$repo = $rm->createRepository('path', ['type' => 'path', 'url' => __DIR__, 'only' => ['foo/bar']]);
|
2020-04-09 11:39:06 +00:00
|
|
|
|
|
|
|
$this->assertInstanceOf('Composer\Repository\FilterRepository', $repo);
|
|
|
|
$this->assertInstanceOf('Composer\Repository\PathRepository', $repo->getRepository());
|
|
|
|
}
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|