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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Repository;
|
|
|
|
|
|
|
|
use Composer\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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
$this->getMock('Composer\IO\IOInterface'),
|
2016-01-26 13:32:04 +00:00
|
|
|
$config = $this->getMock('Composer\Config', array('get')),
|
2013-11-22 10:10:54 +00:00
|
|
|
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
|
|
|
|
);
|
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'));
|
2016-01-26 13:32:04 +00:00
|
|
|
$rm->createRepository($type, $options);
|
2013-11-22 10:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function creationCases()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
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')),
|
|
|
|
array('pear', array('url' => 'http://pear.example.org/foo')),
|
|
|
|
array('artifact', array('url' => '/path/to/zips')),
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|