PerforceTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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\Util;
  12. use Composer\Util\Perforce;
  13. use Composer\Util\ProcessExecutor;
  14. /**
  15. * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  16. */
  17. class PerforceTest extends \PHPUnit_Framework_TestCase
  18. {
  19. protected $perforce;
  20. protected $processExecutor;
  21. protected $io;
  22. public function setUp()
  23. {
  24. $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  25. $repoConfig = array(
  26. 'depot' => 'depot',
  27. 'branch' => 'branch',
  28. 'p4user' => 'user',
  29. 'unique_perforce_client_name' => 'TEST'
  30. );
  31. $io = $this->getMock('Composer\IO\IOInterface');
  32. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, $io);
  33. }
  34. public function tearDown()
  35. {
  36. $this->perforce = null;
  37. $this->io = null;
  38. $this->processExecutor = null;
  39. }
  40. public function testGetClientWithoutStream()
  41. {
  42. $client = $this->perforce->getClient();
  43. $hostname = gethostname();
  44. $timestamp = time();
  45. $expected = 'composer_perforce_TEST_depot';
  46. $this->assertEquals($expected, $client);
  47. }
  48. public function testGetClientFromStream()
  49. {
  50. $this->setPerforceToStream();
  51. $client = $this->perforce->getClient();
  52. $expected = 'composer_perforce_TEST_depot_branch';
  53. $this->assertEquals($expected, $client);
  54. }
  55. public function testGetStreamWithoutStream()
  56. {
  57. $stream = $this->perforce->getStream();
  58. $this->assertEquals("//depot", $stream);
  59. }
  60. public function testGetStreamWithStream()
  61. {
  62. $this->setPerforceToStream();
  63. $stream = $this->perforce->getStream();
  64. $this->assertEquals('//depot/branch', $stream);
  65. }
  66. public function testGetStreamWithoutLabelWithStreamWithoutLabel()
  67. {
  68. $stream = $this->perforce->getStreamWithoutLabel('//depot/branch');
  69. $this->assertEquals('//depot/branch', $stream);
  70. }
  71. public function testGetStreamWithoutLabelWithStreamWithLabel()
  72. {
  73. $stream = $this->perforce->getStreamWithoutLabel('//depot/branching@label');
  74. $this->assertEquals('//depot/branching', $stream);
  75. }
  76. public function testGetClientSpec()
  77. {
  78. $clientSpec = $this->perforce->getP4ClientSpec();
  79. $expected = 'path/composer_perforce_TEST_depot.p4.spec';
  80. $this->assertEquals($expected, $clientSpec);
  81. }
  82. public function testGenerateP4Command()
  83. {
  84. $command = 'do something';
  85. $p4Command = $this->perforce->generateP4Command($command);
  86. $expected = 'p4 -u user -c composer_perforce_TEST_depot -p port do something';
  87. $this->assertEquals($expected, $p4Command);
  88. }
  89. public function testQueryP4UserWithUserAlreadySet()
  90. {
  91. $io = $this->getMock('Composer\IO\IOInterface');
  92. $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'TEST_USER');
  93. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST');
  94. $this->perforce->queryP4user($io);
  95. $this->assertEquals('TEST_USER', $this->perforce->getUser());
  96. }
  97. public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS()
  98. {
  99. $repoConfig = array('depot' => 'depot', 'branch' => 'branch');
  100. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST');
  101. $io = $this->getMock('Composer\IO\IOInterface');
  102. $expectedCommand = 'p4 set';
  103. $this->processExecutor->expects($this->at(0))
  104. ->method('execute')
  105. ->with($this->equalTo($expectedCommand))
  106. ->will(
  107. $this->returnCallback(
  108. function ($command, &$output) {
  109. $output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL ;
  110. return true;
  111. }
  112. )
  113. );
  114. $this->perforce->queryP4user($io);
  115. $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
  116. }
  117. public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS()
  118. {
  119. $repoConfig = array('depot' => 'depot', 'branch' => 'branch');
  120. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST');
  121. $io = $this->getMock('Composer\IO\IOInterface');
  122. $expectedCommand = 'echo $P4USER';
  123. $this->processExecutor->expects($this->at(0))
  124. ->method('execute')
  125. ->with($this->equalTo($expectedCommand))
  126. ->will(
  127. $this->returnCallback(
  128. function ($command, &$output) {
  129. $output = 'TEST_P4VARIABLE_USER' . PHP_EOL;
  130. return true;
  131. }
  132. )
  133. );
  134. $this->perforce->queryP4user($io);
  135. $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
  136. }
  137. public function testQueryP4UserQueriesForUser()
  138. {
  139. $repoConfig = array('depot' => 'depot', 'branch' => 'branch');
  140. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST');
  141. $io = $this->getMock('Composer\IO\IOInterface');
  142. $expectedQuestion = 'Enter P4 User:';
  143. $io->expects($this->at(0))
  144. ->method('ask')
  145. ->with($this->equalTo($expectedQuestion))
  146. ->will($this->returnValue('TEST_QUERY_USER'));
  147. $this->perforce->queryP4user($io);
  148. $this->assertEquals('TEST_QUERY_USER', $this->perforce->getUser());
  149. }
  150. public function testQueryP4UserStoresResponseToQueryForUserWithWindows()
  151. {
  152. $repoConfig = array('depot' => 'depot', 'branch' => 'branch');
  153. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST');
  154. $io = $this->getMock('Composer\IO\IOInterface');
  155. $expectedQuestion = 'Enter P4 User:';
  156. $io->expects($this->at(0))
  157. ->method('ask')
  158. ->with($this->equalTo($expectedQuestion))
  159. ->will($this->returnValue('TEST_QUERY_USER'));
  160. $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER';
  161. $this->processExecutor->expects($this->at(1))
  162. ->method('execute')
  163. ->with($this->equalTo($expectedCommand))
  164. ->will($this->returnValue(0));
  165. $this->perforce->queryP4user($io);
  166. }
  167. public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows()
  168. {
  169. $repoConfig = array('depot' => 'depot', 'branch' => 'branch');
  170. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST');
  171. $io = $this->getMock('Composer\IO\IOInterface');
  172. $expectedQuestion = 'Enter P4 User:';
  173. $io->expects($this->at(0))
  174. ->method('ask')
  175. ->with($this->equalTo($expectedQuestion))
  176. ->will($this->returnValue('TEST_QUERY_USER'));
  177. $expectedCommand = 'export P4USER=TEST_QUERY_USER';
  178. $this->processExecutor->expects($this->at(1))
  179. ->method('execute')
  180. ->with($this->equalTo($expectedCommand))
  181. ->will($this->returnValue(0));
  182. $this->perforce->queryP4user($io);
  183. }
  184. public function testQueryP4PasswordWithPasswordAlreadySet()
  185. {
  186. $repoConfig = array(
  187. 'depot' => 'depot',
  188. 'branch' => 'branch',
  189. 'p4user' => 'user',
  190. 'p4password' => 'TEST_PASSWORD'
  191. );
  192. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST');
  193. $io = $this->getMock('Composer\IO\IOInterface');
  194. $password = $this->perforce->queryP4Password($io);
  195. $this->assertEquals('TEST_PASSWORD', $password);
  196. }
  197. public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS()
  198. {
  199. $io = $this->getMock('Composer\IO\IOInterface');
  200. $expectedCommand = 'p4 set';
  201. $this->processExecutor->expects($this->at(0))
  202. ->method('execute')
  203. ->with($this->equalTo($expectedCommand))
  204. ->will(
  205. $this->returnCallback(
  206. function ($command, &$output) {
  207. $output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
  208. return true;
  209. }
  210. )
  211. );
  212. $password = $this->perforce->queryP4Password($io);
  213. $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
  214. }
  215. public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS()
  216. {
  217. $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'user');
  218. $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST');
  219. $io = $this->getMock('Composer\IO\IOInterface');
  220. $expectedCommand = 'echo $P4PASSWD';
  221. $this->processExecutor->expects($this->at(0))
  222. ->method('execute')
  223. ->with($this->equalTo($expectedCommand))
  224. ->will(
  225. $this->returnCallback(
  226. function ($command, &$output) {
  227. $output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
  228. return true;
  229. }
  230. )
  231. );
  232. $password = $this->perforce->queryP4Password($io);
  233. $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
  234. }
  235. public function testQueryP4PasswordQueriesForPassword()
  236. {
  237. $io = $this->getMock('Composer\IO\IOInterface');
  238. $expectedQuestion = 'Enter password for Perforce user user: ';
  239. $io->expects($this->at(0))
  240. ->method('askAndHideAnswer')
  241. ->with($this->equalTo($expectedQuestion))
  242. ->will($this->returnValue('TEST_QUERY_PASSWORD'));
  243. $password = $this->perforce->queryP4Password($io);
  244. $this->assertEquals('TEST_QUERY_PASSWORD', $password);
  245. }
  246. public function testWriteP4ClientSpecWithoutStream()
  247. {
  248. $stream = fopen('php://memory', 'w+');
  249. $this->perforce->writeClientSpecToFile($stream);
  250. rewind($stream);
  251. $expectedArray = $this->getExpectedClientSpec(false);
  252. try {
  253. foreach ($expectedArray as $expected) {
  254. $this->assertStringStartsWith($expected, fgets($stream));
  255. }
  256. $this->assertFalse(fgets($stream));
  257. } catch (Exception $e) {
  258. fclose($stream);
  259. throw $e;
  260. }
  261. fclose($stream);
  262. }
  263. public function testWriteP4ClientSpecWithStream()
  264. {
  265. $this->setPerforceToStream();
  266. $stream = fopen('php://memory', 'w+');
  267. $this->perforce->writeClientSpecToFile($stream);
  268. rewind($stream);
  269. $expectedArray = $this->getExpectedClientSpec(true);
  270. try {
  271. foreach ($expectedArray as $expected) {
  272. $this->assertStringStartsWith($expected, fgets($stream));
  273. }
  274. $this->assertFalse(fgets($stream));
  275. } catch (Exception $e) {
  276. fclose($stream);
  277. throw $e;
  278. }
  279. fclose($stream);
  280. }
  281. public function testIsLoggedIn()
  282. {
  283. $expectedCommand = 'p4 -u user -p port login -s';
  284. $this->processExecutor->expects($this->at(0))
  285. ->method('execute')
  286. ->with($this->equalTo($expectedCommand), $this->equalTo(null))
  287. ->will($this->returnValue(0));
  288. $this->perforce->isLoggedIn();
  289. }
  290. public function testConnectClient()
  291. {
  292. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec';
  293. $this->processExecutor->expects($this->at(0))
  294. ->method('execute')
  295. ->with($this->equalTo($expectedCommand), $this->equalTo(null))
  296. ->will($this->returnValue(0));
  297. $this->perforce->connectClient();
  298. }
  299. public function testGetBranchesWithStream()
  300. {
  301. $this->setPerforceToStream();
  302. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port streams //depot/...';
  303. $this->processExecutor->expects($this->at(0))
  304. ->method('execute')
  305. ->with($this->equalTo($expectedCommand))
  306. ->will(
  307. $this->returnCallback(
  308. function ($command, &$output) {
  309. $output = 'Stream //depot/branch mainline none \'branch\'' . PHP_EOL;
  310. return true;
  311. }
  312. )
  313. );
  314. $branches = $this->perforce->getBranches();
  315. $this->assertEquals('//depot/branch', $branches['master']);
  316. }
  317. public function testGetBranchesWithoutStream()
  318. {
  319. $branches = $this->perforce->getBranches();
  320. $this->assertEquals('//depot', $branches['master']);
  321. }
  322. public function testGetTagsWithoutStream()
  323. {
  324. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port labels';
  325. $this->processExecutor->expects($this->at(0))
  326. ->method('execute')
  327. ->with($this->equalTo($expectedCommand))
  328. ->will(
  329. $this->returnCallback(
  330. function ($command, &$output) {
  331. $output = 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL;
  332. return true;
  333. }
  334. )
  335. );
  336. $tags = $this->perforce->getTags();
  337. $this->assertEquals('//depot@0.0.1', $tags['0.0.1']);
  338. $this->assertEquals('//depot@0.0.2', $tags['0.0.2']);
  339. }
  340. public function testGetTagsWithStream()
  341. {
  342. $this->setPerforceToStream();
  343. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port labels';
  344. $this->processExecutor->expects($this->at(0))
  345. ->method('execute')
  346. ->with($this->equalTo($expectedCommand))
  347. ->will(
  348. $this->returnCallback(
  349. function ($command, &$output) {
  350. $output = 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL;
  351. return true;
  352. }
  353. )
  354. );
  355. $tags = $this->perforce->getTags();
  356. $this->assertEquals('//depot/branch@0.0.1', $tags['0.0.1']);
  357. $this->assertEquals('//depot/branch@0.0.2', $tags['0.0.2']);
  358. }
  359. public function testCheckStreamWithoutStream()
  360. {
  361. $result = $this->perforce->checkStream('depot');
  362. $this->assertFalse($result);
  363. $this->assertFalse($this->perforce->isStream());
  364. }
  365. public function testCheckStreamWithStream()
  366. {
  367. $this->processExecutor->expects($this->any())->method('execute')
  368. ->will(
  369. $this->returnCallback(
  370. function ($command, &$output) {
  371. $output = 'Depot depot 2013/06/25 stream /p4/1/depots/depot/... \'Created by Me\'';
  372. return true;
  373. }
  374. )
  375. );
  376. $result = $this->perforce->checkStream('depot');
  377. $this->assertTrue($result);
  378. $this->assertTrue($this->perforce->isStream());
  379. }
  380. public function testGetComposerInformationWithoutLabelWithoutStream()
  381. {
  382. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json';
  383. $this->processExecutor->expects($this->at(0))
  384. ->method('execute')
  385. ->with($this->equalTo($expectedCommand))
  386. ->will(
  387. $this->returnCallback(
  388. function ($command, &$output) {
  389. $output = PerforceTest::getComposerJson();
  390. return true;
  391. }
  392. )
  393. );
  394. $result = $this->perforce->getComposerInformation('//depot');
  395. $expected = array(
  396. 'name' => 'test/perforce',
  397. 'description' => 'Basic project for testing',
  398. 'minimum-stability' => 'dev',
  399. 'autoload' => array('psr-0' => array())
  400. );
  401. $this->assertEquals($expected, $result);
  402. }
  403. public function testGetComposerInformationWithLabelWithoutStream()
  404. {
  405. $expectedCommand = 'p4 -u user -p port files //depot/composer.json@0.0.1';
  406. $this->processExecutor->expects($this->at(0))
  407. ->method('execute')
  408. ->with($this->equalTo($expectedCommand))
  409. ->will(
  410. $this->returnCallback(
  411. function ($command, &$output) {
  412. $output = '//depot/composer.json#1 - branch change 10001 (text)';
  413. return true;
  414. }
  415. )
  416. );
  417. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print //depot/composer.json@10001';
  418. $this->processExecutor->expects($this->at(1))
  419. ->method('execute')
  420. ->with($this->equalTo($expectedCommand))
  421. ->will(
  422. $this->returnCallback(
  423. function ($command, &$output) {
  424. $output = PerforceTest::getComposerJson();
  425. return true;
  426. }
  427. )
  428. );
  429. $result = $this->perforce->getComposerInformation('//depot@0.0.1');
  430. $expected = array(
  431. 'name' => 'test/perforce',
  432. 'description' => 'Basic project for testing',
  433. 'minimum-stability' => 'dev',
  434. 'autoload' => array('psr-0' => array())
  435. );
  436. $this->assertEquals($expected, $result);
  437. }
  438. public function testGetComposerInformationWithoutLabelWithStream()
  439. {
  440. $this->setPerforceToStream();
  441. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json';
  442. $this->processExecutor->expects($this->at(0))
  443. ->method('execute')
  444. ->with($this->equalTo($expectedCommand))
  445. ->will(
  446. $this->returnCallback(
  447. function ($command, &$output) {
  448. $output = PerforceTest::getComposerJson();
  449. return true;
  450. }
  451. )
  452. );
  453. $result = $this->perforce->getComposerInformation('//depot/branch');
  454. $expected = array(
  455. 'name' => 'test/perforce',
  456. 'description' => 'Basic project for testing',
  457. 'minimum-stability' => 'dev',
  458. 'autoload' => array('psr-0' => array())
  459. );
  460. $this->assertEquals($expected, $result);
  461. }
  462. public function testGetComposerInformationWithLabelWithStream()
  463. {
  464. $this->setPerforceToStream();
  465. $expectedCommand = 'p4 -u user -p port files //depot/branch/composer.json@0.0.1';
  466. $this->processExecutor->expects($this->at(0))
  467. ->method('execute')
  468. ->with($this->equalTo($expectedCommand))
  469. ->will(
  470. $this->returnCallback(
  471. function ($command, &$output) {
  472. $output = '//depot/composer.json#1 - branch change 10001 (text)';
  473. return true;
  474. }
  475. )
  476. );
  477. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print //depot/branch/composer.json@10001';
  478. $this->processExecutor->expects($this->at(1))
  479. ->method('execute')
  480. ->with($this->equalTo($expectedCommand))
  481. ->will(
  482. $this->returnCallback(
  483. function ($command, &$output) {
  484. $output = PerforceTest::getComposerJson();
  485. return true;
  486. }
  487. )
  488. );
  489. $result = $this->perforce->getComposerInformation('//depot/branch@0.0.1');
  490. $expected = array(
  491. 'name' => 'test/perforce',
  492. 'description' => 'Basic project for testing',
  493. 'minimum-stability' => 'dev',
  494. 'autoload' => array('psr-0' => array())
  495. );
  496. $this->assertEquals($expected, $result);
  497. }
  498. public function testSyncCodeBaseWithoutStream()
  499. {
  500. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label';
  501. $this->processExecutor->expects($this->at(0))
  502. ->method('execute')
  503. ->with($this->equalTo($expectedCommand), $this->equalTo(null))
  504. ->will($this->returnValue(0));
  505. $this->perforce->syncCodeBase('label');
  506. }
  507. public function testSyncCodeBaseWithStream()
  508. {
  509. $this->setPerforceToStream();
  510. $expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label';
  511. $this->processExecutor->expects($this->at(0))
  512. ->method('execute')
  513. ->with($this->equalTo($expectedCommand))
  514. ->will($this->returnValue(0));
  515. $this->perforce->syncCodeBase('label');
  516. }
  517. public function testCheckServerExists()
  518. {
  519. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  520. $expectedCommand = 'p4 -p perforce.does.exist:port info -s';
  521. $processExecutor->expects($this->at(0))
  522. ->method('execute')
  523. ->with($this->equalTo($expectedCommand), $this->equalTo(null))
  524. ->will($this->returnValue(0));
  525. $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
  526. $this->assertTrue($result);
  527. }
  528. /**
  529. * Test if "p4" command is missing.
  530. *
  531. * @covers \Composer\Util\Perforce::checkServerExists
  532. *
  533. * @return void
  534. */
  535. public function testCheckServerClientError()
  536. {
  537. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  538. $expectedCommand = 'p4 -p perforce.does.exist:port info -s';
  539. $processExecutor->expects($this->at(0))
  540. ->method('execute')
  541. ->with($this->equalTo($expectedCommand), $this->equalTo(null))
  542. ->will($this->returnValue(127));
  543. $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
  544. $this->assertFalse($result);
  545. }
  546. public static function getComposerJson()
  547. {
  548. $composer_json = array(
  549. '{',
  550. '"name": "test/perforce",',
  551. '"description": "Basic project for testing",',
  552. '"minimum-stability": "dev",',
  553. '"autoload": {',
  554. '"psr-0" : {',
  555. '}',
  556. '}',
  557. '}'
  558. );
  559. return implode($composer_json);
  560. }
  561. private function getExpectedClientSpec($withStream)
  562. {
  563. $expectedArray = array(
  564. 'Client: composer_perforce_TEST_depot',
  565. PHP_EOL,
  566. 'Update:',
  567. PHP_EOL,
  568. 'Access:',
  569. 'Owner: user',
  570. PHP_EOL,
  571. 'Description:',
  572. ' Created by user from composer.',
  573. PHP_EOL,
  574. 'Root: path',
  575. PHP_EOL,
  576. 'Options: noallwrite noclobber nocompress unlocked modtime rmdir',
  577. PHP_EOL,
  578. 'SubmitOptions: revertunchanged',
  579. PHP_EOL,
  580. 'LineEnd: local',
  581. PHP_EOL
  582. );
  583. if ($withStream) {
  584. $expectedArray[] = 'Stream:';
  585. $expectedArray[] = ' //depot/branch';
  586. } else {
  587. $expectedArray[] = 'View: //depot/... //composer_perforce_TEST_depot/...';
  588. }
  589. return $expectedArray;
  590. }
  591. private function setPerforceToStream()
  592. {
  593. $this->perforce->setStream('//depot/branch');
  594. }
  595. }