PerforceDriverTest.php 4.3 KB

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