PerforceDownloaderTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Created by JetBrains PhpStorm.
  4. * User: matt.whittom
  5. * Date: 8/9/13
  6. * Time: 12:32 PM
  7. * To change this template use File | Settings | File Templates.
  8. */
  9. namespace Composer\Test\Downloader;
  10. use Composer\Downloader\PerforceDownloader;
  11. use Composer\Config;
  12. use Composer\Repository\VcsRepository;
  13. class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase {
  14. private $io;
  15. private $config;
  16. private $testPath;
  17. public static $repository;
  18. function setUp() {
  19. $this->testPath = sys_get_temp_dir() . '/composer-test';
  20. $this->config = new Config();
  21. $this->config->merge(
  22. array(
  23. 'config' => array(
  24. 'home' => $this->testPath,
  25. ),
  26. )
  27. );
  28. $this->io = $this->getMock('Composer\IO\IOInterface');
  29. }
  30. public function testDoDownloadGetRepoConfig() {
  31. $downloader = new PerforceDownloader($this->io, $this->config);
  32. $package = $this->getMock('Composer\Package\PackageInterface' );
  33. $repoConfig = array('url'=>'TEST_URL','p4user'=>'TEST_USER');
  34. $repository = $this->getMock('Composer\Repository\VcsRepository', array('getRepoConfig'), array($repoConfig, $this->io, $this->config));
  35. $package->expects($this->at(0))
  36. ->method('getSourceReference')
  37. ->will($this->returnValue("SOURCE_REF"));
  38. $package->expects($this->at(1))
  39. ->method('getPrettyVersion')
  40. ->will($this->returnValue("100"));
  41. $package->expects($this->at(2))
  42. ->method('getRepository')
  43. ->will($this->returnValue($repository));
  44. $repository->expects($this->at(0))
  45. ->method('getRepoConfig');
  46. $path = $this->testPath;
  47. $downloader->doDownload($package, $path);
  48. }
  49. public function testDoDownload() {
  50. $downloader = new PerforceDownloader($this->io, $this->config);
  51. $repoConfig = array("depot"=>"TEST_DEPOT", "branch"=>"TEST_BRANCH", "p4user"=>"TEST_USER");
  52. $port = "TEST_PORT";
  53. $path = "TEST_PATH";
  54. $process = $this->getmock('Composer\Util\ProcessExecutor');
  55. $perforce = $this->getMock('Composer\Util\Perforce', array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), array($repoConfig, $port, $path, $process, true, "TEST"));
  56. $ref = "SOURCE_REF";
  57. $label = "LABEL";
  58. $perforce->expects($this->at(0))
  59. ->method('setStream')
  60. ->with($this->equalTo($ref));
  61. $perforce->expects($this->at(1))
  62. ->method('queryP4User')
  63. ->with($this->io);
  64. $perforce->expects($this->at(2))
  65. ->method('writeP4ClientSpec');
  66. $perforce->expects($this->at(3))
  67. ->method('connectClient');
  68. $perforce->expects($this->at(4))
  69. ->method('syncCodeBase')
  70. ->with($this->equalTo($label));
  71. $downloader->injectPerforce($perforce);
  72. $package = $this->getMock('Composer\Package\PackageInterface' );
  73. $package->expects($this->at(0))
  74. ->method('getSourceReference')
  75. ->will($this->returnValue($ref));
  76. $package->expects($this->at(1))
  77. ->method('getPrettyVersion')
  78. ->will($this->returnValue($label));
  79. $path = $this->testPath;
  80. $downloader->doDownload($package, $path);
  81. }
  82. }