RepositoryManagerTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\Repository;
  12. use Composer\TestCase;
  13. use Composer\Util\Filesystem;
  14. class RepositoryManagerTest extends TestCase
  15. {
  16. protected $tmpdir;
  17. public function setUp()
  18. {
  19. $this->tmpdir = $this->getUniqueTmpDirectory();
  20. }
  21. public function tearDown()
  22. {
  23. if (is_dir($this->tmpdir)) {
  24. $fs = new Filesystem();
  25. $fs->removeDirectory($this->tmpdir);
  26. }
  27. }
  28. public function testPrepend()
  29. {
  30. $rm = new RepositoryManager(
  31. $this->getMock('Composer\IO\IOInterface'),
  32. $this->getMock('Composer\Config'),
  33. $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
  34. );
  35. $repository1 = $this->getMock('Composer\Repository\RepositoryInterface');
  36. $repository2 = $this->getMock('Composer\Repository\RepositoryInterface');
  37. $rm->addRepository($repository1);
  38. $rm->prependRepository($repository2);
  39. $this->assertEquals(array($repository2, $repository1), $rm->getRepositories());
  40. }
  41. /**
  42. * @dataProvider creationCases
  43. */
  44. public function testRepoCreation($type, $options, $exception = null)
  45. {
  46. if ($exception) {
  47. $this->setExpectedException($exception);
  48. }
  49. $rm = new RepositoryManager(
  50. $this->getMock('Composer\IO\IOInterface'),
  51. $config = $this->getMock('Composer\Config', array('get')),
  52. $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
  53. );
  54. $tmpdir = $this->tmpdir;
  55. $config
  56. ->expects($this->any())
  57. ->method('get')
  58. ->will($this->returnCallback(function ($arg) use ($tmpdir) {
  59. return 'cache-repo-dir' === $arg ? $tmpdir : null;
  60. }))
  61. ;
  62. $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
  63. $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
  64. $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
  65. $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
  66. $rm->setRepositoryClass('git', 'Composer\Repository\VcsRepository');
  67. $rm->setRepositoryClass('svn', 'Composer\Repository\VcsRepository');
  68. $rm->setRepositoryClass('perforce', 'Composer\Repository\VcsRepository');
  69. $rm->setRepositoryClass('hg', 'Composer\Repository\VcsRepository');
  70. $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository');
  71. $rm->createRepository('composer', array('url' => 'http://example.org'));
  72. $rm->createRepository($type, $options);
  73. }
  74. public function creationCases()
  75. {
  76. $cases = array(
  77. array('composer', array('url' => 'http://example.org')),
  78. array('vcs', array('url' => 'http://github.com/foo/bar')),
  79. array('git', array('url' => 'http://github.com/foo/bar')),
  80. array('git', array('url' => 'git@example.org:foo/bar.git')),
  81. array('svn', array('url' => 'svn://example.org/foo/bar')),
  82. array('pear', array('url' => 'http://pear.example.org/foo')),
  83. array('package', array('package' => array())),
  84. array('invalid', array(), 'InvalidArgumentException'),
  85. );
  86. if (class_exists('ZipArchive')) {
  87. $cases[] = array('artifact', array('url' => '/path/to/zips'));
  88. }
  89. return $cases;
  90. }
  91. }