PerforceDownloaderTest.php 3.5 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\Test\Downloader;
  12. use Composer\Downloader\PerforceDownloader;
  13. use Composer\Config;
  14. use Composer\Repository\VcsRepository;
  15. /**
  16. * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  17. */
  18. class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
  19. {
  20. private $io;
  21. private $config;
  22. private $testPath;
  23. public static $repository;
  24. private function setUp()
  25. {
  26. $this->testPath = sys_get_temp_dir() . '/composer-test';
  27. $this->config = new Config();
  28. $this->config->merge(
  29. array(
  30. 'config' => array(
  31. 'home' => $this->testPath,
  32. ),
  33. )
  34. );
  35. $this->io = $this->getMock('Composer\IO\IOInterface');
  36. }
  37. public function testDoDownloadGetRepoConfig()
  38. {
  39. $downloader = new PerforceDownloader($this->io, $this->config);
  40. $package = $this->getMock('Composer\Package\PackageInterface');
  41. $repoConfig = array('url' => 'TEST_URL', 'p4user' => 'TEST_USER');
  42. $repository = $this->getMock(
  43. 'Composer\Repository\VcsRepository',
  44. array('getRepoConfig'),
  45. array($repoConfig, $this->io, $this->config)
  46. );
  47. $package->expects($this->at(0))
  48. ->method('getSourceReference')
  49. ->will($this->returnValue("SOURCE_REF"));
  50. $package->expects($this->at(1))
  51. ->method('getPrettyVersion')
  52. ->will($this->returnValue("100"));
  53. $package->expects($this->at(2))
  54. ->method('getRepository')
  55. ->will($this->returnValue($repository));
  56. $repository->expects($this->at(0))
  57. ->method('getRepoConfig');
  58. $path = $this->testPath;
  59. $downloader->doDownload($package, $path);
  60. }
  61. public function testDoDownload()
  62. {
  63. $downloader = new PerforceDownloader($this->io, $this->config);
  64. $repoConfig = array("depot" => "TEST_DEPOT", "branch" => "TEST_BRANCH", "p4user" => "TEST_USER");
  65. $port = "TEST_PORT";
  66. $path = "TEST_PATH";
  67. $process = $this->getmock('Composer\Util\ProcessExecutor');
  68. $perforce = $this->getMock(
  69. 'Composer\Util\Perforce',
  70. array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'),
  71. array($repoConfig, $port, $path, $process, true, "TEST")
  72. );
  73. $ref = "SOURCE_REF";
  74. $label = "LABEL";
  75. $perforce->expects($this->at(0))
  76. ->method('setStream')
  77. ->with($this->equalTo($ref));
  78. $perforce->expects($this->at(1))
  79. ->method('queryP4User')
  80. ->with($this->io);
  81. $perforce->expects($this->at(2))
  82. ->method('writeP4ClientSpec');
  83. $perforce->expects($this->at(3))
  84. ->method('connectClient');
  85. $perforce->expects($this->at(4))
  86. ->method('syncCodeBase')
  87. ->with($this->equalTo($label));
  88. $downloader->injectPerforce($perforce);
  89. $package = $this->getMock('Composer\Package\PackageInterface');
  90. $package->expects($this->at(0))
  91. ->method('getSourceReference')
  92. ->will($this->returnValue($ref));
  93. $package->expects($this->at(1))
  94. ->method('getPrettyVersion')
  95. ->will($this->returnValue($label));
  96. $path = $this->testPath;
  97. $downloader->doDownload($package, $path);
  98. }
  99. }