1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Refactor repositories handling in config/factory/loader, fixes #828, fixes #826

This commit is contained in:
Jordi Boggiano 2012-06-24 13:03:55 +02:00
parent 74c2fd5f06
commit ffecd39d33
10 changed files with 169 additions and 192 deletions

View file

@ -0,0 +1,102 @@
<?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;
use Composer\Config;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataAddPackagistRepository
*/
public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null)
{
$config = new Config();
if ($systemConfig) {
$config->merge(array('repositories' => $systemConfig));
}
$config->merge(array('repositories' => $localConfig));
$this->assertEquals($expected, $config->getRepositories());
}
public function dataAddPackagistRepository()
{
$data = array();
$data['local config inherits system defaults'] = array(
array(
'packagist' => array('type' => 'composer', 'url' => 'http://packagist.org')
),
array(),
);
$data['local config can disable system config by name'] = array(
array(),
array(
array('packagist' => false),
)
);
$data['local config adds above defaults'] = array(
array(
1 => array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
0 => array('type' => 'pear', 'url' => 'http://pear.composer.org'),
'packagist' => array('type' => 'composer', 'url' => 'http://packagist.org'),
),
array(
array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
array('type' => 'pear', 'url' => 'http://pear.composer.org'),
),
);
$data['system config adds above core defaults'] = array(
array(
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
'packagist' => array('type' => 'composer', 'url' => 'http://packagist.org')
),
array(),
array(
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
),
);
$data['local config can disable repos by name and re-add them anonymously to bring them above system config'] = array(
array(
0 => array('type' => 'composer', 'url' => 'http://packagist.org'),
'example.com' => array('type' => 'composer', 'url' => 'http://example.com')
),
array(
array('packagist' => false),
array('type' => 'composer', 'url' => 'http://packagist.org')
),
array(
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
),
);
$data['local config can override by name to bring a repo above system config'] = array(
array(
'packagist' => array('type' => 'composer', 'url' => 'http://packagistnew.org'),
'example.com' => array('type' => 'composer', 'url' => 'http://example.com')
),
array(
'packagist' => array('type' => 'composer', 'url' => 'http://packagistnew.org')
),
array(
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
),
);
return $data;
}
}

View file

@ -1,93 +0,0 @@
<?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;
use Composer\Factory;
use Composer\Config;
class FactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataAddPackagistRepository
*/
public function testAddPackagistRepository($expected, $composerConfig, $defaults = null)
{
$factory = new Factory();
$config = new Config();
if ($defaults) {
$config->merge(array('repositories' => $defaults));
}
$ref = new \ReflectionMethod($factory, 'addDefaultRepositories');
$ref->setAccessible(true);
$this->assertEquals($expected, $ref->invoke($factory, $config, $composerConfig));
}
public function dataAddPackagistRepository()
{
$repos = function() {
$repositories = func_get_args();
return array('repositories' => $repositories);
};
$data = array();
$data[] = array(
$repos(array('type' => 'composer', 'url' => 'http://packagist.org')),
$repos()
);
$data[] = array(
$repos(array('packagist' => false)),
$repos(array('packagist' => false))
);
$data[] = array(
$repos(
array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
array('type' => 'composer', 'url' => 'http://packagist.org'),
array('type' => 'pear', 'url' => 'http://pear.composer.org')
),
$repos(
array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
array('packagist' => true),
array('type' => 'pear', 'url' => 'http://pear.composer.org')
)
);
$multirepo = array(
'example.com' => 'http://example.com',
);
$data[] = array(
$repos(
array('type' => 'composer', 'url' => 'http://example.com'),
array('type' => 'composer', 'url' => 'http://packagist.org')
),
$repos(),
$multirepo,
);
$data[] = array(
$repos(
array('type' => 'composer', 'url' => 'http://packagist.org'),
array('type' => 'composer', 'url' => 'http://example.com')
),
$repos(array('packagist' => true)),
$multirepo,
);
return $data;
}
}

View file

@ -25,7 +25,10 @@ class FactoryMock extends Factory
{
$config = new Config();
$config->merge(array('config' => array('home' => sys_get_temp_dir().'/composer-test')));
$config->merge(array(
'config' => array('home' => sys_get_temp_dir().'/composer-test'),
'repositories' => array('packagist' => false),
));
return $config;
}
@ -34,11 +37,6 @@ class FactoryMock extends Factory
{
}
protected function addDefaultRepositories(Config $config, array $localConfig)
{
return $localConfig;
}
protected function createInstallationManager(Repository\RepositoryManager $rm, Downloader\DownloadManager $dm, $vendorDir, $binDir, IOInterface $io)
{
return new InstallationManagerMock;

View file

@ -42,25 +42,11 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
return 0;
});
$loader = new RootPackageLoader($manager, new Config, null, $processExecutor);
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
$package = $loader->load(array());
$this->assertEquals("dev-$commitHash", $package->getVersion());
}
public function testAllowsDisabledDefaultRepository()
{
$loader = new RootPackageLoader(
new RepositoryManager(
$this->getMock('Composer\\IO\\IOInterface'),
$this->getMock('Composer\\Config')
),
new Config()
);
$repos = array(array('packagist' => false));
$package = $loader->load(array('repositories' => $repos));
$this->assertEquals($repos, $package->getRepositories());
}
}