FactoryTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Factory;
  13. use Composer\Config;
  14. class FactoryTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @dataProvider dataAddPackagistRepository
  18. */
  19. public function testAddPackagistRepository($expected, $composerConfig, $defaults = null)
  20. {
  21. $factory = new Factory();
  22. $config = new Config();
  23. if ($defaults) {
  24. $config->merge(array('repositories' => $defaults));
  25. }
  26. $ref = new \ReflectionMethod($factory, 'addDefaultRepositories');
  27. $ref->setAccessible(true);
  28. $this->assertEquals($expected, $ref->invoke($factory, $config, $composerConfig));
  29. }
  30. public function dataAddPackagistRepository()
  31. {
  32. $repos = function() {
  33. $repositories = func_get_args();
  34. return array('repositories' => $repositories);
  35. };
  36. $data = array();
  37. $data[] = array(
  38. $repos(array('type' => 'composer', 'url' => 'http://packagist.org')),
  39. $repos()
  40. );
  41. $data[] = array(
  42. $repos(array('packagist' => false)),
  43. $repos(array('packagist' => false))
  44. );
  45. $data[] = array(
  46. $repos(
  47. array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
  48. array('type' => 'composer', 'url' => 'http://packagist.org'),
  49. array('type' => 'pear', 'url' => 'http://pear.composer.org')
  50. ),
  51. $repos(
  52. array('type' => 'vcs', 'url' => 'git://github.com/composer/composer.git'),
  53. array('packagist' => true),
  54. array('type' => 'pear', 'url' => 'http://pear.composer.org')
  55. )
  56. );
  57. $multirepo = array(
  58. 'example.com' => 'http://example.com',
  59. 'packagist' => 'http://packagist.org',
  60. );
  61. $data[] = array(
  62. $repos(
  63. array('type' => 'composer', 'url' => 'http://example.com'),
  64. array('type' => 'composer', 'url' => 'http://packagist.org')
  65. ),
  66. $repos(),
  67. $multirepo,
  68. );
  69. $data[] = array(
  70. $repos(
  71. array('type' => 'composer', 'url' => 'http://packagist.org'),
  72. array('type' => 'composer', 'url' => 'http://example.com')
  73. ),
  74. $repos(array('packagist' => true)),
  75. $multirepo,
  76. );
  77. return $data;
  78. }
  79. }