RepositoryFactoryTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
  22. $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
  23. );
  24. $ref = new \ReflectionProperty($manager, 'repositoryClasses');
  25. $ref->setAccessible(true);
  26. $repositoryClasses = $ref->getValue($manager);
  27. $this->assertEquals(array(
  28. 'composer',
  29. 'vcs',
  30. 'package',
  31. 'pear',
  32. 'git',
  33. 'git-bitbucket',
  34. 'github',
  35. 'gitlab',
  36. 'svn',
  37. 'fossil',
  38. 'perforce',
  39. 'hg',
  40. 'hg-bitbucket',
  41. 'artifact',
  42. 'path',
  43. ), array_keys($repositoryClasses));
  44. }
  45. /**
  46. * @dataProvider generateRepositoryNameProvider
  47. */
  48. public function testGenerateRepositoryName($index, array $config, array $existingRepos, $expected)
  49. {
  50. $this->assertSame($expected, RepositoryFactory::generateRepositoryName($index, $config, $existingRepos));
  51. }
  52. public function generateRepositoryNameProvider()
  53. {
  54. return array(
  55. array(0, array(), array(), 0),
  56. array(0, array(), array(array()), '02'),
  57. array(0, array('url' => 'https://example.org'), array(), 'example.org'),
  58. array(0, array('url' => 'https://example.org'), array('example.org' => array()), 'example.org2'),
  59. array('example.org', array('url' => 'https://example.org/repository'), array(), 'example.org'),
  60. array('example.org', array('url' => 'https://example.org/repository'), array('example.org' => array()), 'example.org2'),
  61. );
  62. }
  63. }