PerforceDriverTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\Repository\Vcs;
  12. use Composer\Repository\Vcs\PerforceDriver;
  13. use Composer\Util\Filesystem;
  14. use Composer\Config;
  15. /**
  16. * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  17. */
  18. class PerforceDriverTest extends \PHPUnit_Framework_TestCase
  19. {
  20. private $config;
  21. private $io;
  22. private $process;
  23. private $remoteFileSystem;
  24. private $testPath;
  25. public function setUp()
  26. {
  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. $this->process = $this->getMock('Composer\Util\ProcessExecutor');
  38. $this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()
  39. ->getMock();
  40. }
  41. public function tearDown()
  42. {
  43. $fs = new Filesystem;
  44. $fs->removeDirectory($this->testPath);
  45. }
  46. public function testInitializeCapturesVariablesFromRepoConfig()
  47. {
  48. $this->setUp();
  49. $repo_config = array(
  50. 'url' => 'TEST_PERFORCE_URL',
  51. 'depot' => 'TEST_DEPOT_CONFIG',
  52. 'branch' => 'TEST_BRANCH_CONFIG'
  53. );
  54. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  55. $process = $this->getMock('Composer\Util\ProcessExecutor');
  56. $arguments = array(
  57. array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
  58. 'port' => 'TEST_PORT',
  59. 'path' => $this->testPath,
  60. $process,
  61. true,
  62. "TEST"
  63. );
  64. $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
  65. $driver->injectPerforce($perforce);
  66. $driver->initialize();
  67. $this->assertEquals("TEST_PERFORCE_URL", $driver->getUrl());
  68. $this->assertEquals("TEST_DEPOT_CONFIG", $driver->getDepot());
  69. $this->assertEquals("TEST_BRANCH_CONFIG", $driver->getBranch());
  70. }
  71. public function testInitializeLogsInAndConnectsClient()
  72. {
  73. $this->setUp();
  74. $repo_config = array(
  75. 'url' => 'TEST_PERFORCE_URL',
  76. 'depot' => 'TEST_DEPOT_CONFIG',
  77. 'branch' => 'TEST_BRANCH_CONFIG'
  78. );
  79. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  80. $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
  81. $perforce->expects($this->at(0))
  82. ->method('p4Login')
  83. ->with($this->io);
  84. $perforce->expects($this->at(1))
  85. ->method('checkStream')
  86. ->with($this->equalTo("TEST_DEPOT_CONFIG"));
  87. $perforce->expects($this->at(2))
  88. ->method('writeP4ClientSpec');
  89. $perforce->expects($this->at(3))
  90. ->method('connectClient');
  91. $driver->injectPerforce($perforce);
  92. $driver->initialize();
  93. }
  94. public function testHasComposerFile()
  95. {
  96. $this->setUp();
  97. $repo_config = array(
  98. 'url' => 'TEST_PERFORCE_URL',
  99. 'depot' => 'TEST_DEPOT_CONFIG',
  100. 'branch' => 'TEST_BRANCH_CONFIG'
  101. );
  102. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  103. $process = $this->getMock('Composer\Util\ProcessExecutor');
  104. $arguments = array(
  105. array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
  106. 'port' => 'TEST_PORT',
  107. 'path' => $this->testPath,
  108. $process,
  109. true,
  110. "TEST"
  111. );
  112. $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
  113. $perforce->expects($this->at(0))
  114. ->method('getComposerInformation')
  115. ->with($this->equalTo("//TEST_DEPOT_CONFIG/TEST_IDENTIFIER"))
  116. ->will($this->returnValue("Some json stuff"));
  117. $driver->injectPerforce($perforce);
  118. $driver->initialize();
  119. $identifier = "TEST_IDENTIFIER";
  120. $result = $driver->hasComposerFile($identifier);
  121. $this->assertTrue($result);
  122. }
  123. }