PerforceDriverTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * Contributor: matt-whittom
  9. * Date: 7/17/13
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace Composer\Test\Repository\Vcs;
  15. #use Composer\Downloader\TransportException;
  16. use Composer\Repository\Vcs\PerforceDriver;
  17. use Composer\Util\Filesystem;
  18. use Composer\Config;
  19. use Composer\IO\ConsoleIO;
  20. use Symfony\Component\Console\Input\ArrayInput;
  21. use Symfony\Component\Console\Output\ConsoleOutput;
  22. use Symfony\Component\Console\Helper\HelperSet;
  23. class PerforceDriverTest extends \PHPUnit_Framework_TestCase
  24. {
  25. private $config;
  26. private $io;
  27. public function setUp()
  28. {
  29. $this->config = new Config();
  30. $this->config->merge(array(
  31. 'config' => array(
  32. 'home' => sys_get_temp_dir() . '/composer-test',
  33. ),
  34. ));
  35. $inputParameters = array();
  36. $input = new ArrayInput($inputParameters);
  37. $output = new ConsoleOutput();
  38. $helperSet = new HelperSet();
  39. $this->io = new ConsoleIO($input, $output, $helperSet);
  40. }
  41. public function tearDown()
  42. {
  43. $fs = new Filesystem;
  44. $fs->removeDirectory(sys_get_temp_dir() . '/composer-test');
  45. }
  46. public function testPrivateRepository()
  47. {
  48. $repo_config = array(
  49. 'url' => "perforce.vuhl.root.mrc.local:3710",
  50. 'depot' => "lighthouse"
  51. );
  52. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  53. $result = $vcs->initialize();
  54. $this->assertTrue($result);
  55. }
  56. public function testGetBranches()
  57. {
  58. $repo_config = array(
  59. 'url' => "perforce.vuhl.root.mrc.local:3710",
  60. 'depot' => "lighthouse"
  61. );
  62. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  63. $result = $vcs->initialize();
  64. $this->assertTrue($result);
  65. $branches = $vcs->getBranches();
  66. //print ("\nBranches are: " . var_export($branches, true));
  67. $this->assertTrue(strcmp($branches['mainline'], "//lighthouse/mainline") == 0);
  68. }
  69. public function testGetTags()
  70. {
  71. $repo_config = array(
  72. 'url' => "perforce.vuhl.root.mrc.local:3710",
  73. 'depot' => "lighthouse"
  74. );
  75. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  76. $result = $vcs->initialize();
  77. $this->assertTrue($result);
  78. $tags = $vcs->getTags();
  79. $this->assertTrue(empty($tags));
  80. }
  81. public function testGetSource()
  82. {
  83. $repo_config = array(
  84. 'url' => "perforce.vuhl.root.mrc.local:3710",
  85. 'depot' => "lighthouse"
  86. );
  87. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  88. $result = $vcs->initialize();
  89. $this->assertTrue($result);
  90. $identifier = $vcs->getRootIdentifier();
  91. $source = $vcs->getSource($identifier);
  92. $this->assertEquals($source['type'], "perforce");
  93. $this->assertEquals($source['reference'], $identifier);
  94. }
  95. public function testGetDist()
  96. {
  97. $repo_config = array(
  98. 'url' => "perforce.vuhl.root.mrc.local:3710",
  99. 'depot' => "lighthouse"
  100. );
  101. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  102. $result = $vcs->initialize();
  103. $this->assertTrue($result);
  104. $identifier = $vcs->getRootIdentifier();
  105. $dist = $vcs->getDist($identifier);
  106. $this->assertNull($dist);
  107. }
  108. public function testGetRootIdentifier(){
  109. $repo_config = array(
  110. 'url' => "perforce.vuhl.root.mrc.local:3710",
  111. 'depot' => "lighthouse"
  112. );
  113. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  114. $result = $vcs->initialize();
  115. $this->assertTrue($result);
  116. $rootId = $vcs->getRootIdentifier();
  117. $this->assertEquals("mainline", $rootId);
  118. }
  119. public function testHasComposerFile(){
  120. $repo_config = array(
  121. 'url' => "perforce.vuhl.root.mrc.local:3710",
  122. 'depot' => "lighthouse"
  123. );
  124. $vcs = new PerforceDriver($repo_config, $this->io, $this->config);
  125. $result = $vcs->initialize();
  126. $this->assertTrue($result);
  127. $identifier = $vcs->getRootIdentifier();
  128. $value = $vcs->hasComposerFile($identifier);
  129. $this->assertTrue($value);
  130. }
  131. }