PerforceDownloaderTest.php 3.4 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. * 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. protected 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 testInitPerforceGetRepoConfig()
  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('getRepository')
  49. ->will($this->returnValue($repository));
  50. $repository->expects($this->at(0))
  51. ->method('getRepoConfig');
  52. $path = $this->testPath;
  53. $downloader->initPerforce($package, $path, 'SOURCE_REF');
  54. }
  55. public function testDoDownload()
  56. {
  57. $downloader = new PerforceDownloader($this->io, $this->config);
  58. $repoConfig = array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH', 'p4user' => 'TEST_USER');
  59. $port = 'TEST_PORT';
  60. $path = 'TEST_PATH';
  61. $process = $this->getmock('Composer\Util\ProcessExecutor');
  62. $perforce = $this->getMock(
  63. 'Composer\Util\Perforce',
  64. array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'),
  65. array($repoConfig, $port, $path, $process, true, 'TEST')
  66. );
  67. $ref = 'SOURCE_REF';
  68. $label = 'LABEL';
  69. $perforce->expects($this->at(0))
  70. ->method('setStream')
  71. ->with($this->equalTo($ref));
  72. $perforce->expects($this->at(1))
  73. ->method('queryP4User')
  74. ->with($this->io);
  75. $perforce->expects($this->at(2))
  76. ->method('writeP4ClientSpec');
  77. $perforce->expects($this->at(3))
  78. ->method('connectClient');
  79. $perforce->expects($this->at(4))
  80. ->method('syncCodeBase')
  81. ->with($this->equalTo($label));
  82. $downloader->setPerforce($perforce);
  83. $package = $this->getMock('Composer\Package\PackageInterface');
  84. $package->expects($this->at(0))
  85. ->method('getSourceReference')
  86. ->will($this->returnValue($ref));
  87. $package->expects($this->at(1))
  88. ->method('getPrettyVersion')
  89. ->will($this->returnValue($label));
  90. $path = $this->testPath;
  91. $downloader->doDownload($package, $path);
  92. }
  93. }