GitDownloaderTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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\Downloader;
  12. use Composer\Downloader\GitDownloader;
  13. use Composer\Config;
  14. use Composer\TestCase;
  15. use Composer\Util\Filesystem;
  16. use Composer\Util\Platform;
  17. class GitDownloaderTest extends TestCase
  18. {
  19. /** @var Filesystem */
  20. private $fs;
  21. /** @var string */
  22. private $workingDir;
  23. protected function setUp()
  24. {
  25. $this->fs = new Filesystem;
  26. $this->workingDir = $this->getUniqueTmpDirectory();
  27. }
  28. protected function tearDown()
  29. {
  30. if (is_dir($this->workingDir)) {
  31. $this->fs->removeDirectory($this->workingDir);
  32. }
  33. }
  34. protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
  35. {
  36. $io = $io ?: $this->getMock('Composer\IO\IOInterface');
  37. $executor = $executor ?: $this->getMock('Composer\Util\ProcessExecutor');
  38. $filesystem = $filesystem ?: $this->getMock('Composer\Util\Filesystem');
  39. if (!$config) {
  40. $config = new Config();
  41. }
  42. if (!$config->has('home')) {
  43. $tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true));
  44. $config->merge(array('config' => array('home' => $tmpDir)));
  45. }
  46. return new GitDownloader($io, $config, $executor, $filesystem);
  47. }
  48. /**
  49. * @expectedException \InvalidArgumentException
  50. */
  51. public function testDownloadForPackageWithoutSourceReference()
  52. {
  53. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  54. $packageMock->expects($this->once())
  55. ->method('getSourceReference')
  56. ->will($this->returnValue(null));
  57. $downloader = $this->getDownloaderMock();
  58. $downloader->download($packageMock, '/path');
  59. }
  60. public function testDownload()
  61. {
  62. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  63. $packageMock->expects($this->any())
  64. ->method('getSourceReference')
  65. ->will($this->returnValue('1234567890123456789012345678901234567890'));
  66. $packageMock->expects($this->any())
  67. ->method('getSourceUrls')
  68. ->will($this->returnValue(array('https://example.com/composer/composer')));
  69. $packageMock->expects($this->any())
  70. ->method('getSourceUrl')
  71. ->will($this->returnValue('https://example.com/composer/composer'));
  72. $packageMock->expects($this->any())
  73. ->method('getPrettyVersion')
  74. ->will($this->returnValue('dev-master'));
  75. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  76. $expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://example.com/composer/composer' && git fetch composer");
  77. $processExecutor->expects($this->at(0))
  78. ->method('execute')
  79. ->with($this->equalTo($expectedGitCommand))
  80. ->will($this->returnValue(0));
  81. $processExecutor->expects($this->at(1))
  82. ->method('execute')
  83. ->with($this->equalTo($this->winCompat("git branch -r")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  84. ->will($this->returnValue(0));
  85. $processExecutor->expects($this->at(2))
  86. ->method('execute')
  87. ->with($this->equalTo($this->winCompat("git checkout 'master' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  88. ->will($this->returnValue(0));
  89. $processExecutor->expects($this->at(3))
  90. ->method('execute')
  91. ->with($this->equalTo($this->winCompat("git reset --hard '1234567890123456789012345678901234567890' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  92. ->will($this->returnValue(0));
  93. $downloader = $this->getDownloaderMock(null, null, $processExecutor);
  94. $downloader->download($packageMock, 'composerPath');
  95. }
  96. public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub()
  97. {
  98. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  99. $packageMock->expects($this->any())
  100. ->method('getSourceReference')
  101. ->will($this->returnValue('ref'));
  102. $packageMock->expects($this->any())
  103. ->method('getSourceUrls')
  104. ->will($this->returnValue(array('https://github.com/mirrors/composer', 'https://github.com/composer/composer')));
  105. $packageMock->expects($this->any())
  106. ->method('getSourceUrl')
  107. ->will($this->returnValue('https://github.com/composer/composer'));
  108. $packageMock->expects($this->any())
  109. ->method('getPrettyVersion')
  110. ->will($this->returnValue('1.0.0'));
  111. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  112. $expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://github.com/mirrors/composer' && git fetch composer");
  113. $processExecutor->expects($this->at(0))
  114. ->method('execute')
  115. ->with($this->equalTo($expectedGitCommand))
  116. ->will($this->returnValue(1));
  117. $processExecutor->expects($this->at(1))
  118. ->method('getErrorOutput')
  119. ->with()
  120. ->will($this->returnValue('Error1'));
  121. $expectedGitCommand = $this->winCompat("git clone --no-checkout 'git@github.com:mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'git@github.com:mirrors/composer' && git fetch composer");
  122. $processExecutor->expects($this->at(2))
  123. ->method('execute')
  124. ->with($this->equalTo($expectedGitCommand))
  125. ->will($this->returnValue(0));
  126. $expectedGitCommand = $this->winCompat("git remote set-url origin 'https://github.com/composer/composer'");
  127. $processExecutor->expects($this->at(3))
  128. ->method('execute')
  129. ->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  130. ->will($this->returnValue(0));
  131. $expectedGitCommand = $this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'");
  132. $processExecutor->expects($this->at(4))
  133. ->method('execute')
  134. ->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  135. ->will($this->returnValue(0));
  136. $processExecutor->expects($this->at(5))
  137. ->method('execute')
  138. ->with($this->equalTo('git branch -r'))
  139. ->will($this->returnValue(0));
  140. $processExecutor->expects($this->at(6))
  141. ->method('execute')
  142. ->with($this->equalTo($this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  143. ->will($this->returnValue(0));
  144. $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
  145. $downloader->download($packageMock, 'composerPath');
  146. }
  147. public function pushUrlProvider()
  148. {
  149. return array(
  150. // ssh proto should use git@ all along
  151. array(array('ssh'), 'git@github.com:composer/composer', 'git@github.com:composer/composer.git'),
  152. // auto-proto uses git@ by default for push url, but not fetch
  153. array(array('https', 'ssh', 'git'), 'https://github.com/composer/composer', 'git@github.com:composer/composer.git'),
  154. // if restricted to https then push url is not overwritten to git@
  155. array(array('https'), 'https://github.com/composer/composer', 'https://github.com/composer/composer.git'),
  156. );
  157. }
  158. /**
  159. * @dataProvider pushUrlProvider
  160. */
  161. public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocols, $url, $pushUrl)
  162. {
  163. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  164. $packageMock->expects($this->any())
  165. ->method('getSourceReference')
  166. ->will($this->returnValue('ref'));
  167. $packageMock->expects($this->any())
  168. ->method('getSourceUrls')
  169. ->will($this->returnValue(array('https://github.com/composer/composer')));
  170. $packageMock->expects($this->any())
  171. ->method('getSourceUrl')
  172. ->will($this->returnValue('https://github.com/composer/composer'));
  173. $packageMock->expects($this->any())
  174. ->method('getPrettyVersion')
  175. ->will($this->returnValue('1.0.0'));
  176. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  177. $expectedGitCommand = $this->winCompat("git clone --no-checkout '{$url}' 'composerPath' && cd 'composerPath' && git remote add composer '{$url}' && git fetch composer");
  178. $processExecutor->expects($this->at(0))
  179. ->method('execute')
  180. ->with($this->equalTo($expectedGitCommand))
  181. ->will($this->returnValue(0));
  182. $expectedGitCommand = $this->winCompat("git remote set-url --push origin '{$pushUrl}'");
  183. $processExecutor->expects($this->at(1))
  184. ->method('execute')
  185. ->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
  186. ->will($this->returnValue(0));
  187. $processExecutor->expects($this->exactly(4))
  188. ->method('execute')
  189. ->will($this->returnValue(0));
  190. $config = new Config();
  191. $config->merge(array('config' => array('github-protocols' => $protocols)));
  192. $downloader = $this->getDownloaderMock(null, $config, $processExecutor);
  193. $downloader->download($packageMock, 'composerPath');
  194. }
  195. /**
  196. * @expectedException \RuntimeException
  197. */
  198. public function testDownloadThrowsRuntimeExceptionIfGitCommandFails()
  199. {
  200. $expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://example.com/composer/composer' && git fetch composer");
  201. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  202. $packageMock->expects($this->any())
  203. ->method('getSourceReference')
  204. ->will($this->returnValue('ref'));
  205. $packageMock->expects($this->any())
  206. ->method('getSourceUrls')
  207. ->will($this->returnValue(array('https://example.com/composer/composer')));
  208. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  209. $processExecutor->expects($this->at(0))
  210. ->method('execute')
  211. ->with($this->equalTo($expectedGitCommand))
  212. ->will($this->returnValue(1));
  213. $downloader = $this->getDownloaderMock(null, null, $processExecutor);
  214. $downloader->download($packageMock, 'composerPath');
  215. }
  216. /**
  217. * @expectedException \InvalidArgumentException
  218. */
  219. public function testUpdateforPackageWithoutSourceReference()
  220. {
  221. $initialPackageMock = $this->getMock('Composer\Package\PackageInterface');
  222. $sourcePackageMock = $this->getMock('Composer\Package\PackageInterface');
  223. $sourcePackageMock->expects($this->once())
  224. ->method('getSourceReference')
  225. ->will($this->returnValue(null));
  226. $downloader = $this->getDownloaderMock();
  227. $downloader->update($initialPackageMock, $sourcePackageMock, '/path');
  228. }
  229. public function testUpdate()
  230. {
  231. $expectedGitUpdateCommand = $this->winCompat("git remote set-url composer 'https://github.com/composer/composer' && git fetch composer && git fetch --tags composer");
  232. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  233. $packageMock->expects($this->any())
  234. ->method('getSourceReference')
  235. ->will($this->returnValue('ref'));
  236. $packageMock->expects($this->any())
  237. ->method('getSourceUrls')
  238. ->will($this->returnValue(array('https://github.com/composer/composer')));
  239. $packageMock->expects($this->any())
  240. ->method('getPrettyVersion')
  241. ->will($this->returnValue('1.0.0'));
  242. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  243. $processExecutor->expects($this->at(0))
  244. ->method('execute')
  245. ->with($this->equalTo($this->winCompat("git show-ref --head -d")))
  246. ->will($this->returnValue(0));
  247. $processExecutor->expects($this->at(1))
  248. ->method('execute')
  249. ->with($this->equalTo($this->winCompat("git status --porcelain --untracked-files=no")))
  250. ->will($this->returnValue(0));
  251. $processExecutor->expects($this->at(2))
  252. ->method('execute')
  253. ->with($this->equalTo($this->winCompat("git remote -v")))
  254. ->will($this->returnValue(0));
  255. $processExecutor->expects($this->at(3))
  256. ->method('execute')
  257. ->with($this->equalTo($this->winCompat("git remote -v")))
  258. ->will($this->returnValue(0));
  259. $processExecutor->expects($this->at(4))
  260. ->method('execute')
  261. ->with($this->equalTo($this->winCompat($expectedGitUpdateCommand)), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  262. ->will($this->returnValue(0));
  263. $processExecutor->expects($this->at(5))
  264. ->method('execute')
  265. ->with($this->equalTo('git branch -r'))
  266. ->will($this->returnValue(0));
  267. $processExecutor->expects($this->at(6))
  268. ->method('execute')
  269. ->with($this->equalTo($this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  270. ->will($this->returnValue(0));
  271. $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
  272. $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
  273. $downloader->update($packageMock, $packageMock, $this->workingDir);
  274. }
  275. public function testUpdateWithNewRepoUrl()
  276. {
  277. $expectedGitUpdateCommand = $this->winCompat("git remote set-url composer 'https://github.com/composer/composer' && git fetch composer && git fetch --tags composer");
  278. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  279. $packageMock->expects($this->any())
  280. ->method('getSourceReference')
  281. ->will($this->returnValue('ref'));
  282. $packageMock->expects($this->any())
  283. ->method('getSourceUrls')
  284. ->will($this->returnValue(array('https://github.com/composer/composer')));
  285. $packageMock->expects($this->any())
  286. ->method('getSourceUrl')
  287. ->will($this->returnValue('https://github.com/composer/composer'));
  288. $packageMock->expects($this->any())
  289. ->method('getPrettyVersion')
  290. ->will($this->returnValue('1.0.0'));
  291. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  292. $processExecutor->expects($this->at(0))
  293. ->method('execute')
  294. ->with($this->equalTo($this->winCompat("git show-ref --head -d")))
  295. ->will($this->returnValue(0));
  296. $processExecutor->expects($this->at(1))
  297. ->method('execute')
  298. ->with($this->equalTo($this->winCompat("git status --porcelain --untracked-files=no")))
  299. ->will($this->returnValue(0));
  300. $processExecutor->expects($this->at(2))
  301. ->method('execute')
  302. ->with($this->equalTo($this->winCompat("git remote -v")))
  303. ->will($this->returnCallback(function ($cmd, &$output, $cwd) {
  304. $output = 'origin https://github.com/old/url (fetch)
  305. origin https://github.com/old/url (push)
  306. composer https://github.com/old/url (fetch)
  307. composer https://github.com/old/url (push)
  308. ';
  309. return 0;
  310. }));
  311. $processExecutor->expects($this->at(3))
  312. ->method('execute')
  313. ->with($this->equalTo($this->winCompat("git remote -v")))
  314. ->will($this->returnValue(0));
  315. $processExecutor->expects($this->at(4))
  316. ->method('execute')
  317. ->with($this->equalTo($this->winCompat($expectedGitUpdateCommand)), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  318. ->will($this->returnValue(0));
  319. $processExecutor->expects($this->at(5))
  320. ->method('execute')
  321. ->with($this->equalTo('git branch -r'))
  322. ->will($this->returnValue(0));
  323. $processExecutor->expects($this->at(6))
  324. ->method('execute')
  325. ->with($this->equalTo($this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  326. ->will($this->returnValue(0));
  327. $processExecutor->expects($this->at(7))
  328. ->method('execute')
  329. ->with($this->equalTo($this->winCompat("git remote set-url origin 'https://github.com/composer/composer'")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  330. ->will($this->returnValue(0));
  331. $processExecutor->expects($this->at(8))
  332. ->method('execute')
  333. ->with($this->equalTo($this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  334. ->will($this->returnValue(0));
  335. $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
  336. $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
  337. $downloader->update($packageMock, $packageMock, $this->workingDir);
  338. }
  339. /**
  340. * @group failing
  341. * @expectedException \RuntimeException
  342. */
  343. public function testUpdateThrowsRuntimeExceptionIfGitCommandFails()
  344. {
  345. $expectedGitUpdateCommand = $this->winCompat("git remote set-url composer 'https://github.com/composer/composer' && git fetch composer && git fetch --tags composer");
  346. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  347. $packageMock->expects($this->any())
  348. ->method('getSourceReference')
  349. ->will($this->returnValue('ref'));
  350. $packageMock->expects($this->any())
  351. ->method('getSourceUrls')
  352. ->will($this->returnValue(array('https://github.com/composer/composer')));
  353. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  354. $processExecutor->expects($this->at(0))
  355. ->method('execute')
  356. ->with($this->equalTo($this->winCompat("git show-ref --head -d")))
  357. ->will($this->returnValue(0));
  358. $processExecutor->expects($this->at(1))
  359. ->method('execute')
  360. ->with($this->equalTo($this->winCompat("git status --porcelain --untracked-files=no")))
  361. ->will($this->returnValue(0));
  362. $processExecutor->expects($this->at(2))
  363. ->method('execute')
  364. ->with($this->equalTo($this->winCompat("git remote -v")))
  365. ->will($this->returnValue(0));
  366. $processExecutor->expects($this->at(3))
  367. ->method('execute')
  368. ->with($this->equalTo($this->winCompat("git remote -v")))
  369. ->will($this->returnValue(0));
  370. $processExecutor->expects($this->at(4))
  371. ->method('execute')
  372. ->with($this->equalTo($expectedGitUpdateCommand))
  373. ->will($this->returnValue(1));
  374. $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
  375. $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
  376. $downloader->update($packageMock, $packageMock, $this->workingDir);
  377. }
  378. public function testUpdateDoesntThrowsRuntimeExceptionIfGitCommandFailsAtFirstButIsAbleToRecover()
  379. {
  380. $expectedFirstGitUpdateCommand = $this->winCompat("git remote set-url composer '' && git fetch composer && git fetch --tags composer");
  381. $expectedSecondGitUpdateCommand = $this->winCompat("git remote set-url composer 'https://github.com/composer/composer' && git fetch composer && git fetch --tags composer");
  382. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  383. $packageMock->expects($this->any())
  384. ->method('getSourceReference')
  385. ->will($this->returnValue('ref'));
  386. $packageMock->expects($this->any())
  387. ->method('getSourceUrls')
  388. ->will($this->returnValue(array('/foo/bar', 'https://github.com/composer/composer')));
  389. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  390. $processExecutor->expects($this->at(0))
  391. ->method('execute')
  392. ->with($this->equalTo($this->winCompat("git show-ref --head -d")))
  393. ->will($this->returnValue(0));
  394. $processExecutor->expects($this->at(1))
  395. ->method('execute')
  396. ->with($this->equalTo($this->winCompat("git status --porcelain --untracked-files=no")))
  397. ->will($this->returnValue(0));
  398. $processExecutor->expects($this->at(2))
  399. ->method('execute')
  400. ->with($this->equalTo($this->winCompat("git remote -v")))
  401. ->will($this->returnValue(0));
  402. $processExecutor->expects($this->at(3))
  403. ->method('execute')
  404. ->with($this->equalTo($this->winCompat("git remote -v")))
  405. ->will($this->returnValue(0));
  406. $processExecutor->expects($this->at(4))
  407. ->method('execute')
  408. ->with($this->equalTo($expectedFirstGitUpdateCommand))
  409. ->will($this->returnValue(1));
  410. $processExecutor->expects($this->at(6))
  411. ->method('execute')
  412. ->with($this->equalTo($this->winCompat("git --version")))
  413. ->will($this->returnValue(0));
  414. $processExecutor->expects($this->at(7))
  415. ->method('execute')
  416. ->with($this->equalTo($this->winCompat("git remote -v")))
  417. ->will($this->returnValue(0));
  418. $processExecutor->expects($this->at(8))
  419. ->method('execute')
  420. ->with($this->equalTo($this->winCompat("git remote -v")))
  421. ->will($this->returnValue(0));
  422. $processExecutor->expects($this->at(9))
  423. ->method('execute')
  424. ->with($this->equalTo($expectedSecondGitUpdateCommand))
  425. ->will($this->returnValue(0));
  426. $processExecutor->expects($this->at(11))
  427. ->method('execute')
  428. ->with($this->equalTo($this->winCompat("git checkout 'ref' -- && git reset --hard 'ref' --")), $this->equalTo(null), $this->equalTo($this->winCompat($this->workingDir)))
  429. ->will($this->returnValue(0));
  430. $this->fs->ensureDirectoryExists($this->workingDir.'/.git');
  431. $downloader = $this->getDownloaderMock(null, new Config(), $processExecutor);
  432. $downloader->update($packageMock, $packageMock, $this->workingDir);
  433. }
  434. public function testRemove()
  435. {
  436. $expectedGitResetCommand = $this->winCompat("cd 'composerPath' && git status --porcelain --untracked-files=no");
  437. $packageMock = $this->getMock('Composer\Package\PackageInterface');
  438. $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
  439. $processExecutor->expects($this->any())
  440. ->method('execute')
  441. ->with($this->equalTo($expectedGitResetCommand))
  442. ->will($this->returnValue(0));
  443. $filesystem = $this->getMock('Composer\Util\Filesystem');
  444. $filesystem->expects($this->any())
  445. ->method('removeDirectory')
  446. ->with($this->equalTo('composerPath'))
  447. ->will($this->returnValue(true));
  448. $downloader = $this->getDownloaderMock(null, null, $processExecutor, $filesystem);
  449. $downloader->remove($packageMock, 'composerPath');
  450. }
  451. public function testGetInstallationSource()
  452. {
  453. $downloader = $this->getDownloaderMock();
  454. $this->assertEquals('source', $downloader->getInstallationSource());
  455. }
  456. private function winCompat($cmd)
  457. {
  458. if (Platform::isWindows()) {
  459. $cmd = str_replace('cd ', 'cd /D ', $cmd);
  460. $cmd = str_replace('composerPath', getcwd().'/composerPath', $cmd);
  461. return str_replace('""', '', strtr($cmd, "'", '"'));
  462. }
  463. return $cmd;
  464. }
  465. }