PerforceDriverTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. $repoConfig = array(
  50. 'url' => 'TEST_PERFORCE_URL',
  51. 'depot' => 'TEST_DEPOT_CONFIG',
  52. 'branch' => 'TEST_BRANCH_CONFIG'
  53. );
  54. $driver = new PerforceDriver($repoConfig, $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->setPerforce($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. $repoConfig = array(
  75. 'url' => 'TEST_PERFORCE_URL',
  76. 'depot' => 'TEST_DEPOT_CONFIG',
  77. 'branch' => 'TEST_BRANCH_CONFIG'
  78. );
  79. $driver = new PerforceDriver($repoConfig, $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->setPerforce($perforce);
  92. $driver->initialize();
  93. }
  94. public function testHasComposerFile()
  95. {
  96. $repoConfig = array(
  97. 'url' => 'TEST_PERFORCE_URL',
  98. 'depot' => 'TEST_DEPOT_CONFIG',
  99. 'branch' => 'TEST_BRANCH_CONFIG'
  100. );
  101. $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  102. $process = $this->getMock('Composer\Util\ProcessExecutor');
  103. $arguments = array(
  104. array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
  105. 'port' => 'TEST_PORT',
  106. 'path' => $this->testPath,
  107. $process,
  108. true,
  109. 'TEST'
  110. );
  111. $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
  112. $perforce->expects($this->at(0))
  113. ->method('getComposerInformation')
  114. ->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER'))
  115. ->will($this->returnValue('Some json stuff'));
  116. $driver->setPerforce($perforce);
  117. $driver->initialize();
  118. $identifier = 'TEST_IDENTIFIER';
  119. $result = $driver->hasComposerFile($identifier);
  120. $this->assertTrue($result);
  121. }
  122. /**
  123. * Test that supports() simply return false.
  124. *
  125. * @covers \Composer\Repository\Vcs\PerforceDriver::supports
  126. *
  127. * @return void
  128. */
  129. public function testSupportsReturnsFalseNoDeepCheck()
  130. {
  131. $this->expectOutputString('');
  132. $this->assertFalse(PerforceDriver::supports($this->io, 'existing.url', $this->config));
  133. }
  134. }