RepositoryManagerTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  29. * @dataProvider creationCases
  30. */
  31. public function testRepoCreation($type, $options, $exception = null)
  32. {
  33. if ($exception) {
  34. $this->setExpectedException($exception);
  35. }
  36. $rm = new RepositoryManager(
  37. $this->getMock('Composer\IO\IOInterface'),
  38. $config = $this->getMock('Composer\Config', array('get')),
  39. $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
  40. );
  41. $tmpdir = $this->tmpdir;
  42. $config
  43. ->expects($this->any())
  44. ->method('get')
  45. ->will($this->returnCallback(function ($arg) use ($tmpdir) {
  46. return 'cache-repo-dir' === $arg ? $tmpdir : null;
  47. }))
  48. ;
  49. $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
  50. $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
  51. $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
  52. $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository');
  53. $rm->setRepositoryClass('git', 'Composer\Repository\VcsRepository');
  54. $rm->setRepositoryClass('svn', 'Composer\Repository\VcsRepository');
  55. $rm->setRepositoryClass('perforce', 'Composer\Repository\VcsRepository');
  56. $rm->setRepositoryClass('hg', 'Composer\Repository\VcsRepository');
  57. $rm->setRepositoryClass('artifact', 'Composer\Repository\ArtifactRepository');
  58. $rm->createRepository('composer', array('url' => 'http://example.org'));
  59. $rm->createRepository($type, $options);
  60. }
  61. public function creationCases()
  62. {
  63. $cases = array(
  64. array('composer', array('url' => 'http://example.org')),
  65. array('vcs', array('url' => 'http://github.com/foo/bar')),
  66. array('git', array('url' => 'http://github.com/foo/bar')),
  67. array('git', array('url' => 'git@example.org:foo/bar.git')),
  68. array('svn', array('url' => 'svn://example.org/foo/bar')),
  69. array('pear', array('url' => 'http://pear.example.org/foo')),
  70. array('package', array('package' => array())),
  71. array('invalid', array(), 'InvalidArgumentException'),
  72. );
  73. if (class_exists('ZipArchive')) {
  74. $cases[] = array('artifact', array('url' => '/path/to/zips'));
  75. }
  76. return $cases;
  77. }
  78. }