PerforceDriverTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. * Contributor: matt-whittom
  9. * Date: 7/17/13
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace Composer\Test\Repository\Vcs;
  15. use Composer\Repository\Vcs\PerforceDriver;
  16. use Composer\Util\Filesystem;
  17. use Composer\Config;
  18. /**
  19. * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  20. */
  21. class PerforceDriverTest extends \PHPUnit_Framework_TestCase {
  22. private $config;
  23. private $io;
  24. private $process;
  25. private $remoteFileSystem;
  26. private $testPath;
  27. public function setUp() {
  28. $this->testPath = sys_get_temp_dir() . '/composer-test';
  29. $this->config = new Config();
  30. $this->config->merge(
  31. array(
  32. 'config' => array(
  33. 'home' => $this->testPath,
  34. ),
  35. )
  36. );
  37. $this->io = $this->getMock('Composer\IO\IOInterface');
  38. $this->process = $this->getMock('Composer\Util\ProcessExecutor');
  39. $this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()->getMock();
  40. }
  41. public function tearDown() {
  42. $fs = new Filesystem;
  43. $fs->removeDirectory($this->testPath);
  44. }
  45. public function testInitializeCapturesVariablesFromRepoConfig() {
  46. $this->setUp();
  47. $repo_config = array(
  48. 'url' => 'TEST_PERFORCE_URL',
  49. 'depot' => 'TEST_DEPOT_CONFIG',
  50. 'branch' => 'TEST_BRANCH_CONFIG'
  51. );
  52. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  53. $process = $this->getMock('Composer\Util\ProcessExecutor');
  54. $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath, $process, true, "TEST");
  55. $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
  56. $driver->injectPerforce($perforce);
  57. $driver->initialize();
  58. $this->assertEquals("TEST_PERFORCE_URL", $driver->getUrl());
  59. $this->assertEquals("TEST_DEPOT_CONFIG", $driver->getDepot());
  60. $this->assertEquals("TEST_BRANCH_CONFIG", $driver->getBranch());
  61. }
  62. public function testInitializeLogsInAndConnectsClient() {
  63. $this->setUp();
  64. $repo_config = array(
  65. 'url' => 'TEST_PERFORCE_URL',
  66. 'depot' => 'TEST_DEPOT_CONFIG',
  67. 'branch' => 'TEST_BRANCH_CONFIG'
  68. );
  69. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  70. $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
  71. $perforce->expects($this->at(0))
  72. ->method('p4Login')
  73. ->with($this->io);
  74. $perforce->expects($this->at(1))
  75. ->method('checkStream')
  76. ->with($this->equalTo("TEST_DEPOT_CONFIG"));
  77. $perforce->expects($this->at(2))
  78. ->method('writeP4ClientSpec');
  79. $perforce->expects($this->at(3))
  80. ->method('connectClient');
  81. $driver->injectPerforce($perforce);
  82. $driver->initialize();
  83. }
  84. public function testHasComposerFile() {
  85. $this->setUp();
  86. $repo_config = array(
  87. 'url' => 'TEST_PERFORCE_URL',
  88. 'depot' => 'TEST_DEPOT_CONFIG',
  89. 'branch' => 'TEST_BRANCH_CONFIG'
  90. );
  91. $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  92. $process = $this->getMock('Composer\Util\ProcessExecutor');
  93. $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath, $process, true, "TEST");
  94. $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
  95. $perforce->expects($this->at(0))
  96. ->method('getComposerInformation')
  97. ->with($this->equalTo("//TEST_DEPOT_CONFIG/TEST_IDENTIFIER"))
  98. ->will($this->returnValue("Some json stuff"));
  99. $driver->injectPerforce($perforce);
  100. $driver->initialize();
  101. $identifier = "TEST_IDENTIFIER";
  102. $result = $driver->hasComposerFile($identifier);
  103. $this->assertTrue($result);
  104. }
  105. }