PerforceTest.php 24 KB

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