ConfigTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test;
  12. use Composer\Config;
  13. class ConfigTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @dataProvider dataAddPackagistRepository
  17. */
  18. public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null)
  19. {
  20. $config = new Config();
  21. if ($systemConfig) {
  22. $config->merge(array('repositories' => $systemConfig));
  23. }
  24. $config->merge(array('repositories' => $localConfig));
  25. $this->assertEquals($expected, $config->getRepositories());
  26. }
  27. public function dataAddPackagistRepository()
  28. {
  29. $data = array();
  30. $data['local config inherits system defaults'] = array(
  31. array(
  32. 'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true)
  33. ),
  34. array(),
  35. );
  36. $data['local config can disable system config by name'] = array(
  37. array(),
  38. array(
  39. array('packagist' => false),
  40. )
  41. );
  42. $data['local config adds above defaults'] = array(
  43. array(
  44. 1 => array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
  45. 0 => array('type' => 'pear', 'url' => 'http://pear.composer.org'),
  46. 'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true),
  47. ),
  48. array(
  49. array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
  50. array('type' => 'pear', 'url' => 'http://pear.composer.org'),
  51. ),
  52. );
  53. $data['system config adds above core defaults'] = array(
  54. array(
  55. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
  56. 'packagist' => array('type' => 'composer', 'url' => 'https?://packagist.org', 'allow_ssl_downgrade' => true)
  57. ),
  58. array(),
  59. array(
  60. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
  61. ),
  62. );
  63. $data['local config can disable repos by name and re-add them anonymously to bring them above system config'] = array(
  64. array(
  65. 0 => array('type' => 'composer', 'url' => 'http://packagist.org'),
  66. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com')
  67. ),
  68. array(
  69. array('packagist' => false),
  70. array('type' => 'composer', 'url' => 'http://packagist.org')
  71. ),
  72. array(
  73. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
  74. ),
  75. );
  76. $data['local config can override by name to bring a repo above system config'] = array(
  77. array(
  78. 'packagist' => array('type' => 'composer', 'url' => 'http://packagistnew.org'),
  79. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com')
  80. ),
  81. array(
  82. 'packagist' => array('type' => 'composer', 'url' => 'http://packagistnew.org')
  83. ),
  84. array(
  85. 'example.com' => array('type' => 'composer', 'url' => 'http://example.com'),
  86. ),
  87. );
  88. return $data;
  89. }
  90. public function testMergeGithubOauth()
  91. {
  92. $config = new Config();
  93. $config->merge(array('config' => array('github-oauth' => array('foo' => 'bar'))));
  94. $config->merge(array('config' => array('github-oauth' => array('bar' => 'baz'))));
  95. $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $config->get('github-oauth'));
  96. }
  97. public function testOverrideGithubProtocols()
  98. {
  99. $config = new Config();
  100. $config->merge(array('config' => array('github-protocols' => array('https', 'git'))));
  101. $config->merge(array('config' => array('github-protocols' => array('https'))));
  102. $this->assertEquals(array('https'), $config->get('github-protocols'));
  103. }
  104. }