PerforceDownloaderTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $perforce = $this->getMock('Composer\Util\Perforce', array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), array($repoConfig, $port, $path));
  55. $ref = "SOURCE_REF";
  56. $label = "LABEL";
  57. $perforce->expects($this->at(0))
  58. ->method('setStream')
  59. ->with($this->equalTo($ref));
  60. $perforce->expects($this->at(1))
  61. ->method('queryP4User')
  62. ->with($this->io);
  63. $perforce->expects($this->at(2))
  64. ->method('writeP4ClientSpec');
  65. $perforce->expects($this->at(3))
  66. ->method('connectClient');
  67. $perforce->expects($this->at(4))
  68. ->method('syncCodeBase')
  69. ->with($this->equalTo($label));
  70. $downloader->injectPerforce($perforce);
  71. $package = $this->getMock('Composer\Package\PackageInterface' );
  72. $package->expects($this->at(0))
  73. ->method('getSourceReference')
  74. ->will($this->returnValue($ref));
  75. $package->expects($this->at(1))
  76. ->method('getPrettyVersion')
  77. ->will($this->returnValue($label));
  78. $path = $this->testPath;
  79. $downloader->doDownload($package, $path);
  80. }
  81. }