PerforceDriverTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. //Test:
  43. //hasComposerFile
  44. public function testInitializeCapturesVariablesFromRepoConfig() {
  45. $this->setUp();
  46. $repo_config = array(
  47. 'url' => 'TEST_PERFORCE_URL',
  48. 'depot' => 'TEST_DEPOT_CONFIG',
  49. 'branch' => 'TEST_BRANCH_CONFIG'
  50. );
  51. $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  52. $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
  53. $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
  54. $driver->injectPerforce($perforce);
  55. $driver->initialize();
  56. $this->assertEquals("TEST_PERFORCE_URL", $driver->getUrl());
  57. $this->assertEquals("TEST_DEPOT_CONFIG", $driver->getDepot());
  58. $this->assertEquals("TEST_BRANCH_CONFIG", $driver->getBranch());
  59. }
  60. public function testInitializeLogsInAndConnectsClient() {
  61. $this->setUp();
  62. $repo_config = array(
  63. 'url' => 'TEST_PERFORCE_URL',
  64. 'depot' => 'TEST_DEPOT_CONFIG',
  65. 'branch' => 'TEST_BRANCH_CONFIG'
  66. );
  67. $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  68. $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
  69. $perforce->expects($this->at(0))
  70. ->method('p4Login')
  71. ->with($this->io);
  72. $perforce->expects($this->at(1))
  73. ->method('checkStream')
  74. ->with($this->equalTo("TEST_DEPOT_CONFIG"));
  75. $perforce->expects($this->at(2))
  76. ->method('writeP4ClientSpec');
  77. $perforce->expects($this->at(3))
  78. ->method('connectClient');
  79. $driver->injectPerforce($perforce);
  80. $driver->initialize();
  81. }
  82. public function testHasComposerFile() {
  83. $this->setUp();
  84. $repo_config = array(
  85. 'url' => 'TEST_PERFORCE_URL',
  86. 'depot' => 'TEST_DEPOT_CONFIG',
  87. 'branch' => 'TEST_BRANCH_CONFIG'
  88. );
  89. $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
  90. $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
  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. }