FactoryTest.php 2.9 KB

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