RepositoryFactoryTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Repository;
  12. use Composer\Repository\RepositoryFactory;
  13. use Composer\Test\TestCase;
  14. class RepositoryFactoryTest extends TestCase
  15. {
  16. public function testManagerWithAllRepositoryTypes()
  17. {
  18. $manager = RepositoryFactory::manager(
  19. $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
  20. $this->getMockBuilder('Composer\Config')->getMock()
  21. );
  22. $ref = new \ReflectionProperty($manager, 'repositoryClasses');
  23. $ref->setAccessible(true);
  24. $repositoryClasses = $ref->getValue($manager);
  25. $this->assertEquals(array(
  26. 'composer',
  27. 'vcs',
  28. 'package',
  29. 'pear',
  30. 'git',
  31. 'git-bitbucket',
  32. 'github',
  33. 'gitlab',
  34. 'svn',
  35. 'fossil',
  36. 'perforce',
  37. 'hg',
  38. 'hg-bitbucket',
  39. 'artifact',
  40. 'path',
  41. ), array_keys($repositoryClasses));
  42. }
  43. /**
  44. * @dataProvider generateRepositoryNameProvider
  45. */
  46. public function testGenerateRepositoryName($index, array $config, array $existingRepos, $expected)
  47. {
  48. $this->assertSame($expected, RepositoryFactory::generateRepositoryName($index, $config, $existingRepos));
  49. }
  50. public function generateRepositoryNameProvider()
  51. {
  52. return array(
  53. array(0, array(), array(), 0),
  54. array(0, array(), array(array()), '02'),
  55. array(0, array('url' => 'https://example.org'), array(), 'example.org'),
  56. array(0, array('url' => 'https://example.org'), array('example.org' => array()), 'example.org2'),
  57. array('example.org', array('url' => 'https://example.org/repository'), array(), 'example.org'),
  58. array('example.org', array('url' => 'https://example.org/repository'), array('example.org' => array()), 'example.org2'),
  59. );
  60. }
  61. }