PerforceDownloaderTest.php 3.6 KB

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