2012-06-24 11:03:55 +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\Test;
|
|
|
|
|
|
|
|
use Composer\Config;
|
|
|
|
|
|
|
|
class ConfigTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider dataAddPackagistRepository
|
|
|
|
*/
|
|
|
|
public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null)
|
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2012-06-24 11:03:55 +00:00
|
|
|
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(
|
2015-09-28 09:51:14 +00:00
|
|
|
'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$data['local config can disable system config by name'] = array(
|
|
|
|
array(),
|
|
|
|
array(
|
|
|
|
array('packagist' => false),
|
2015-09-28 09:51:14 +00:00
|
|
|
),
|
2012-06-24 11:03:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$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'),
|
2013-02-21 16:45:03 +00:00
|
|
|
'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
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'),
|
2015-09-28 09:51:14 +00:00
|
|
|
'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
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'),
|
2015-09-28 09:51:14 +00:00
|
|
|
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('packagist' => false),
|
2015-09-28 09:51:14 +00:00
|
|
|
array('type' => 'composer', 'url' => 'http://packagist.org'),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
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'),
|
2015-09-28 09:51:14 +00:00
|
|
|
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
array(
|
2015-09-28 09:51:14 +00:00
|
|
|
'packagist' => array('type' => 'composer', 'url' => 'http://packagistnew.org'),
|
2012-06-24 11:03:55 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2015-01-20 10:03:55 +00:00
|
|
|
$data['incorrect local config does not cause ErrorException'] = array(
|
|
|
|
array(
|
|
|
|
'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true),
|
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://example.com',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'type' => 'vcs',
|
|
|
|
'url' => 'http://example.com',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2012-06-24 11:03:55 +00:00
|
|
|
return $data;
|
|
|
|
}
|
2012-12-08 20:45:21 +00:00
|
|
|
|
|
|
|
public function testMergeGithubOauth()
|
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2012-12-08 20:45:21 +00:00
|
|
|
$config->merge(array('config' => array('github-oauth' => array('foo' => 'bar'))));
|
|
|
|
$config->merge(array('config' => array('github-oauth' => array('bar' => 'baz'))));
|
|
|
|
|
|
|
|
$this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $config->get('github-oauth'));
|
|
|
|
}
|
|
|
|
|
2014-06-29 12:47:43 +00:00
|
|
|
public function testVarReplacement()
|
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2014-06-29 12:47:43 +00:00
|
|
|
$config->merge(array('config' => array('a' => 'b', 'c' => '{$a}')));
|
|
|
|
$config->merge(array('config' => array('bin-dir' => '$HOME', 'cache-dir' => '~/foo/')));
|
|
|
|
|
2014-09-30 14:17:53 +00:00
|
|
|
$home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '\\/');
|
2014-06-29 12:47:43 +00:00
|
|
|
$this->assertEquals('b', $config->get('c'));
|
|
|
|
$this->assertEquals($home.'/', $config->get('bin-dir'));
|
|
|
|
$this->assertEquals($home.'/foo', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2014-12-16 11:12:13 +00:00
|
|
|
public function testRealpathReplacement()
|
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
|
|
|
$config->merge(array('config' => array(
|
|
|
|
'bin-dir' => '$HOME/foo',
|
|
|
|
'cache-dir' => '/baz/',
|
2015-09-28 09:51:14 +00:00
|
|
|
'vendor-dir' => 'vendor',
|
2014-12-16 11:12:13 +00:00
|
|
|
)));
|
|
|
|
|
|
|
|
$home = rtrim(getenv('HOME') ?: getenv('USERPROFILE'), '\\/');
|
|
|
|
$this->assertEquals('/foo/bar/vendor', $config->get('vendor-dir'));
|
|
|
|
$this->assertEquals($home.'/foo', $config->get('bin-dir'));
|
|
|
|
$this->assertEquals('/baz', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2016-01-25 23:40:16 +00:00
|
|
|
public function testStreamWrapperDirs()
|
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
|
|
|
$config->merge(array('config' => array(
|
|
|
|
'cache-dir' => 's3://baz/',
|
|
|
|
)));
|
|
|
|
|
|
|
|
$this->assertEquals('s3://baz', $config->get('cache-dir'));
|
|
|
|
}
|
|
|
|
|
2014-12-17 21:57:27 +00:00
|
|
|
public function testFetchingRelativePaths()
|
|
|
|
{
|
|
|
|
$config = new Config(false, '/foo/bar');
|
|
|
|
$config->merge(array('config' => array(
|
|
|
|
'bin-dir' => '{$vendor-dir}/foo',
|
2015-09-28 09:51:14 +00:00
|
|
|
'vendor-dir' => 'vendor',
|
2014-12-17 21:57:27 +00:00
|
|
|
)));
|
|
|
|
|
|
|
|
$this->assertEquals('/foo/bar/vendor', $config->get('vendor-dir'));
|
|
|
|
$this->assertEquals('/foo/bar/vendor/foo', $config->get('bin-dir'));
|
|
|
|
$this->assertEquals('vendor', $config->get('vendor-dir', Config::RELATIVE_PATHS));
|
|
|
|
$this->assertEquals('vendor/foo', $config->get('bin-dir', Config::RELATIVE_PATHS));
|
|
|
|
}
|
|
|
|
|
2012-12-08 20:45:21 +00:00
|
|
|
public function testOverrideGithubProtocols()
|
|
|
|
{
|
2014-11-21 10:15:17 +00:00
|
|
|
$config = new Config(false);
|
2013-06-28 18:42:06 +00:00
|
|
|
$config->merge(array('config' => array('github-protocols' => array('https', 'git'))));
|
|
|
|
$config->merge(array('config' => array('github-protocols' => array('https'))));
|
2012-12-08 20:45:21 +00:00
|
|
|
|
2013-06-28 18:42:06 +00:00
|
|
|
$this->assertEquals(array('https'), $config->get('github-protocols'));
|
2012-12-08 20:45:21 +00:00
|
|
|
}
|
2014-02-23 10:20:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group TLS
|
|
|
|
*/
|
|
|
|
public function testDisableTlsCanBeOverridden()
|
|
|
|
{
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(
|
|
|
|
array('config' => array('disable-tls' => 'false'))
|
|
|
|
);
|
|
|
|
$this->assertFalse($config->get('disable-tls'));
|
|
|
|
$config->merge(
|
|
|
|
array('config' => array('disable-tls' => 'true'))
|
|
|
|
);
|
|
|
|
$this->assertTrue($config->get('disable-tls'));
|
|
|
|
}
|
2012-06-24 11:03:55 +00:00
|
|
|
}
|