FactoryTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. );
  60. $data[] = array(
  61. $repos(
  62. array('type' => 'composer', 'url' => 'http://example.com'),
  63. array('type' => 'composer', 'url' => 'http://packagist.org')
  64. ),
  65. $repos(),
  66. $multirepo,
  67. );
  68. $data[] = array(
  69. $repos(
  70. array('type' => 'composer', 'url' => 'http://packagist.org'),
  71. array('type' => 'composer', 'url' => 'http://example.com')
  72. ),
  73. $repos(array('packagist' => true)),
  74. $multirepo,
  75. );
  76. return $data;
  77. }
  78. }