DownloadManagerTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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\DownloadManager;
  13. class DownloadManagerTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $filesystem;
  16. protected $io;
  17. public function setUp()
  18. {
  19. $this->filesystem = $this->getMock('Composer\Util\Filesystem');
  20. $this->io = $this->getMock('Composer\IO\IOInterface');
  21. }
  22. public function testSetGetDownloader()
  23. {
  24. $downloader = $this->createDownloaderMock();
  25. $manager = new DownloadManager($this->io, false, $this->filesystem);
  26. $manager->setDownloader('test', $downloader);
  27. $this->assertSame($downloader, $manager->getDownloader('test'));
  28. $this->setExpectedException('InvalidArgumentException');
  29. $manager->getDownloader('unregistered');
  30. }
  31. public function testGetDownloaderForIncorrectlyInstalledPackage()
  32. {
  33. $package = $this->createPackageMock();
  34. $package
  35. ->expects($this->once())
  36. ->method('getInstallationSource')
  37. ->will($this->returnValue(null));
  38. $manager = new DownloadManager($this->io, false, $this->filesystem);
  39. $this->setExpectedException('InvalidArgumentException');
  40. $manager->getDownloaderForInstalledPackage($package);
  41. }
  42. public function testGetDownloaderForCorrectlyInstalledDistPackage()
  43. {
  44. $package = $this->createPackageMock();
  45. $package
  46. ->expects($this->once())
  47. ->method('getInstallationSource')
  48. ->will($this->returnValue('dist'));
  49. $package
  50. ->expects($this->once())
  51. ->method('getDistType')
  52. ->will($this->returnValue('pear'));
  53. $downloader = $this->createDownloaderMock();
  54. $downloader
  55. ->expects($this->once())
  56. ->method('getInstallationSource')
  57. ->will($this->returnValue('dist'));
  58. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  59. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  60. ->setMethods(array('getDownloader'))
  61. ->getMock();
  62. $manager
  63. ->expects($this->once())
  64. ->method('getDownloader')
  65. ->with('pear')
  66. ->will($this->returnValue($downloader));
  67. $this->assertSame($downloader, $manager->getDownloaderForInstalledPackage($package));
  68. }
  69. public function testGetDownloaderForIncorrectlyInstalledDistPackage()
  70. {
  71. $package = $this->createPackageMock();
  72. $package
  73. ->expects($this->once())
  74. ->method('getInstallationSource')
  75. ->will($this->returnValue('dist'));
  76. $package
  77. ->expects($this->once())
  78. ->method('getDistType')
  79. ->will($this->returnValue('git'));
  80. $downloader = $this->createDownloaderMock();
  81. $downloader
  82. ->expects($this->exactly(2))
  83. ->method('getInstallationSource')
  84. ->will($this->returnValue('source'));
  85. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  86. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  87. ->setMethods(array('getDownloader'))
  88. ->getMock();
  89. $manager
  90. ->expects($this->once())
  91. ->method('getDownloader')
  92. ->with('git')
  93. ->will($this->returnValue($downloader));
  94. $this->setExpectedException('LogicException');
  95. $manager->getDownloaderForInstalledPackage($package);
  96. }
  97. public function testGetDownloaderForCorrectlyInstalledSourcePackage()
  98. {
  99. $package = $this->createPackageMock();
  100. $package
  101. ->expects($this->once())
  102. ->method('getInstallationSource')
  103. ->will($this->returnValue('source'));
  104. $package
  105. ->expects($this->once())
  106. ->method('getSourceType')
  107. ->will($this->returnValue('git'));
  108. $downloader = $this->createDownloaderMock();
  109. $downloader
  110. ->expects($this->once())
  111. ->method('getInstallationSource')
  112. ->will($this->returnValue('source'));
  113. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  114. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  115. ->setMethods(array('getDownloader'))
  116. ->getMock();
  117. $manager
  118. ->expects($this->once())
  119. ->method('getDownloader')
  120. ->with('git')
  121. ->will($this->returnValue($downloader));
  122. $this->assertSame($downloader, $manager->getDownloaderForInstalledPackage($package));
  123. }
  124. public function testGetDownloaderForIncorrectlyInstalledSourcePackage()
  125. {
  126. $package = $this->createPackageMock();
  127. $package
  128. ->expects($this->once())
  129. ->method('getInstallationSource')
  130. ->will($this->returnValue('source'));
  131. $package
  132. ->expects($this->once())
  133. ->method('getSourceType')
  134. ->will($this->returnValue('pear'));
  135. $downloader = $this->createDownloaderMock();
  136. $downloader
  137. ->expects($this->exactly(2))
  138. ->method('getInstallationSource')
  139. ->will($this->returnValue('dist'));
  140. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  141. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  142. ->setMethods(array('getDownloader'))
  143. ->getMock();
  144. $manager
  145. ->expects($this->once())
  146. ->method('getDownloader')
  147. ->with('pear')
  148. ->will($this->returnValue($downloader));
  149. $this->setExpectedException('LogicException');
  150. $manager->getDownloaderForInstalledPackage($package);
  151. }
  152. public function testGetDownloaderForMetapackage()
  153. {
  154. $package = $this->createPackageMock();
  155. $package
  156. ->expects($this->once())
  157. ->method('getType')
  158. ->will($this->returnValue('metapackage'));
  159. $manager = new DownloadManager($this->io, false, $this->filesystem);
  160. $this->assertNull($manager->getDownloaderForInstalledPackage($package));
  161. }
  162. public function testFullPackageDownload()
  163. {
  164. $package = $this->createPackageMock();
  165. $package
  166. ->expects($this->once())
  167. ->method('getSourceType')
  168. ->will($this->returnValue('git'));
  169. $package
  170. ->expects($this->once())
  171. ->method('getDistType')
  172. ->will($this->returnValue('pear'));
  173. $package
  174. ->expects($this->once())
  175. ->method('setInstallationSource')
  176. ->with('dist');
  177. $downloader = $this->createDownloaderMock();
  178. $downloader
  179. ->expects($this->once())
  180. ->method('download')
  181. ->with($package, 'target_dir');
  182. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  183. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  184. ->setMethods(array('getDownloaderForInstalledPackage'))
  185. ->getMock();
  186. $manager
  187. ->expects($this->once())
  188. ->method('getDownloaderForInstalledPackage')
  189. ->with($package)
  190. ->will($this->returnValue($downloader));
  191. $manager->download($package, 'target_dir');
  192. }
  193. public function testFullPackageDownloadFailover()
  194. {
  195. $package = $this->createPackageMock();
  196. $package
  197. ->expects($this->once())
  198. ->method('getSourceType')
  199. ->will($this->returnValue('git'));
  200. $package
  201. ->expects($this->once())
  202. ->method('getDistType')
  203. ->will($this->returnValue('pear'));
  204. $package
  205. ->expects($this->any())
  206. ->method('getPrettyString')
  207. ->will($this->returnValue('prettyPackage'));
  208. $package
  209. ->expects($this->at(3))
  210. ->method('setInstallationSource')
  211. ->with('dist');
  212. $package
  213. ->expects($this->at(5))
  214. ->method('setInstallationSource')
  215. ->with('source');
  216. $downloaderFail = $this->createDownloaderMock();
  217. $downloaderFail
  218. ->expects($this->once())
  219. ->method('download')
  220. ->with($package, 'target_dir')
  221. ->will($this->throwException(new \RuntimeException("Foo")));
  222. $downloaderSuccess = $this->createDownloaderMock();
  223. $downloaderSuccess
  224. ->expects($this->once())
  225. ->method('download')
  226. ->with($package, 'target_dir');
  227. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  228. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  229. ->setMethods(array('getDownloaderForInstalledPackage'))
  230. ->getMock();
  231. $manager
  232. ->expects($this->at(0))
  233. ->method('getDownloaderForInstalledPackage')
  234. ->with($package)
  235. ->will($this->returnValue($downloaderFail));
  236. $manager
  237. ->expects($this->at(1))
  238. ->method('getDownloaderForInstalledPackage')
  239. ->with($package)
  240. ->will($this->returnValue($downloaderSuccess));
  241. $manager->download($package, 'target_dir');
  242. }
  243. public function testBadPackageDownload()
  244. {
  245. $package = $this->createPackageMock();
  246. $package
  247. ->expects($this->once())
  248. ->method('getSourceType')
  249. ->will($this->returnValue(null));
  250. $package
  251. ->expects($this->once())
  252. ->method('getDistType')
  253. ->will($this->returnValue(null));
  254. $manager = new DownloadManager($this->io, false, $this->filesystem);
  255. $this->setExpectedException('InvalidArgumentException');
  256. $manager->download($package, 'target_dir');
  257. }
  258. public function testDistOnlyPackageDownload()
  259. {
  260. $package = $this->createPackageMock();
  261. $package
  262. ->expects($this->once())
  263. ->method('getSourceType')
  264. ->will($this->returnValue(null));
  265. $package
  266. ->expects($this->once())
  267. ->method('getDistType')
  268. ->will($this->returnValue('pear'));
  269. $package
  270. ->expects($this->once())
  271. ->method('setInstallationSource')
  272. ->with('dist');
  273. $downloader = $this->createDownloaderMock();
  274. $downloader
  275. ->expects($this->once())
  276. ->method('download')
  277. ->with($package, 'target_dir');
  278. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  279. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  280. ->setMethods(array('getDownloaderForInstalledPackage'))
  281. ->getMock();
  282. $manager
  283. ->expects($this->once())
  284. ->method('getDownloaderForInstalledPackage')
  285. ->with($package)
  286. ->will($this->returnValue($downloader));
  287. $manager->download($package, 'target_dir');
  288. }
  289. public function testSourceOnlyPackageDownload()
  290. {
  291. $package = $this->createPackageMock();
  292. $package
  293. ->expects($this->once())
  294. ->method('getSourceType')
  295. ->will($this->returnValue('git'));
  296. $package
  297. ->expects($this->once())
  298. ->method('getDistType')
  299. ->will($this->returnValue(null));
  300. $package
  301. ->expects($this->once())
  302. ->method('setInstallationSource')
  303. ->with('source');
  304. $downloader = $this->createDownloaderMock();
  305. $downloader
  306. ->expects($this->once())
  307. ->method('download')
  308. ->with($package, 'target_dir');
  309. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  310. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  311. ->setMethods(array('getDownloaderForInstalledPackage'))
  312. ->getMock();
  313. $manager
  314. ->expects($this->once())
  315. ->method('getDownloaderForInstalledPackage')
  316. ->with($package)
  317. ->will($this->returnValue($downloader));
  318. $manager->download($package, 'target_dir');
  319. }
  320. public function testMetapackagePackageDownload()
  321. {
  322. $package = $this->createPackageMock();
  323. $package
  324. ->expects($this->once())
  325. ->method('getSourceType')
  326. ->will($this->returnValue('git'));
  327. $package
  328. ->expects($this->once())
  329. ->method('getDistType')
  330. ->will($this->returnValue(null));
  331. $package
  332. ->expects($this->once())
  333. ->method('setInstallationSource')
  334. ->with('source');
  335. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  336. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  337. ->setMethods(array('getDownloaderForInstalledPackage'))
  338. ->getMock();
  339. $manager
  340. ->expects($this->once())
  341. ->method('getDownloaderForInstalledPackage')
  342. ->with($package)
  343. ->will($this->returnValue(null)); // There is no downloader for Metapackages.
  344. $manager->download($package, 'target_dir');
  345. }
  346. public function testFullPackageDownloadWithSourcePreferred()
  347. {
  348. $package = $this->createPackageMock();
  349. $package
  350. ->expects($this->once())
  351. ->method('getSourceType')
  352. ->will($this->returnValue('git'));
  353. $package
  354. ->expects($this->once())
  355. ->method('getDistType')
  356. ->will($this->returnValue('pear'));
  357. $package
  358. ->expects($this->once())
  359. ->method('setInstallationSource')
  360. ->with('source');
  361. $downloader = $this->createDownloaderMock();
  362. $downloader
  363. ->expects($this->once())
  364. ->method('download')
  365. ->with($package, 'target_dir');
  366. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  367. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  368. ->setMethods(array('getDownloaderForInstalledPackage'))
  369. ->getMock();
  370. $manager
  371. ->expects($this->once())
  372. ->method('getDownloaderForInstalledPackage')
  373. ->with($package)
  374. ->will($this->returnValue($downloader));
  375. $manager->setPreferSource(true);
  376. $manager->download($package, 'target_dir');
  377. }
  378. public function testDistOnlyPackageDownloadWithSourcePreferred()
  379. {
  380. $package = $this->createPackageMock();
  381. $package
  382. ->expects($this->once())
  383. ->method('getSourceType')
  384. ->will($this->returnValue(null));
  385. $package
  386. ->expects($this->once())
  387. ->method('getDistType')
  388. ->will($this->returnValue('pear'));
  389. $package
  390. ->expects($this->once())
  391. ->method('setInstallationSource')
  392. ->with('dist');
  393. $downloader = $this->createDownloaderMock();
  394. $downloader
  395. ->expects($this->once())
  396. ->method('download')
  397. ->with($package, 'target_dir');
  398. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  399. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  400. ->setMethods(array('getDownloaderForInstalledPackage'))
  401. ->getMock();
  402. $manager
  403. ->expects($this->once())
  404. ->method('getDownloaderForInstalledPackage')
  405. ->with($package)
  406. ->will($this->returnValue($downloader));
  407. $manager->setPreferSource(true);
  408. $manager->download($package, 'target_dir');
  409. }
  410. public function testSourceOnlyPackageDownloadWithSourcePreferred()
  411. {
  412. $package = $this->createPackageMock();
  413. $package
  414. ->expects($this->once())
  415. ->method('getSourceType')
  416. ->will($this->returnValue('git'));
  417. $package
  418. ->expects($this->once())
  419. ->method('getDistType')
  420. ->will($this->returnValue(null));
  421. $package
  422. ->expects($this->once())
  423. ->method('setInstallationSource')
  424. ->with('source');
  425. $downloader = $this->createDownloaderMock();
  426. $downloader
  427. ->expects($this->once())
  428. ->method('download')
  429. ->with($package, 'target_dir');
  430. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  431. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  432. ->setMethods(array('getDownloaderForInstalledPackage'))
  433. ->getMock();
  434. $manager
  435. ->expects($this->once())
  436. ->method('getDownloaderForInstalledPackage')
  437. ->with($package)
  438. ->will($this->returnValue($downloader));
  439. $manager->setPreferSource(true);
  440. $manager->download($package, 'target_dir');
  441. }
  442. public function testBadPackageDownloadWithSourcePreferred()
  443. {
  444. $package = $this->createPackageMock();
  445. $package
  446. ->expects($this->once())
  447. ->method('getSourceType')
  448. ->will($this->returnValue(null));
  449. $package
  450. ->expects($this->once())
  451. ->method('getDistType')
  452. ->will($this->returnValue(null));
  453. $manager = new DownloadManager($this->io, false, $this->filesystem);
  454. $manager->setPreferSource(true);
  455. $this->setExpectedException('InvalidArgumentException');
  456. $manager->download($package, 'target_dir');
  457. }
  458. public function testUpdateDistWithEqualTypes()
  459. {
  460. $initial = $this->createPackageMock();
  461. $initial
  462. ->expects($this->once())
  463. ->method('getInstallationSource')
  464. ->will($this->returnValue('dist'));
  465. $initial
  466. ->expects($this->once())
  467. ->method('getDistType')
  468. ->will($this->returnValue('pear'));
  469. $target = $this->createPackageMock();
  470. $target
  471. ->expects($this->once())
  472. ->method('getDistType')
  473. ->will($this->returnValue('pear'));
  474. $target
  475. ->expects($this->once())
  476. ->method('setInstallationSource')
  477. ->with('dist');
  478. $pearDownloader = $this->createDownloaderMock();
  479. $pearDownloader
  480. ->expects($this->once())
  481. ->method('update')
  482. ->with($initial, $target, 'vendor/bundles/FOS/UserBundle');
  483. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  484. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  485. ->setMethods(array('getDownloaderForInstalledPackage'))
  486. ->getMock();
  487. $manager
  488. ->expects($this->once())
  489. ->method('getDownloaderForInstalledPackage')
  490. ->with($initial)
  491. ->will($this->returnValue($pearDownloader));
  492. $manager->update($initial, $target, 'vendor/bundles/FOS/UserBundle');
  493. }
  494. public function testUpdateDistWithNotEqualTypes()
  495. {
  496. $initial = $this->createPackageMock();
  497. $initial
  498. ->expects($this->once())
  499. ->method('getInstallationSource')
  500. ->will($this->returnValue('dist'));
  501. $initial
  502. ->expects($this->once())
  503. ->method('getDistType')
  504. ->will($this->returnValue('pear'));
  505. $target = $this->createPackageMock();
  506. $target
  507. ->expects($this->once())
  508. ->method('getDistType')
  509. ->will($this->returnValue('composer'));
  510. $pearDownloader = $this->createDownloaderMock();
  511. $pearDownloader
  512. ->expects($this->once())
  513. ->method('remove')
  514. ->with($initial, 'vendor/bundles/FOS/UserBundle');
  515. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  516. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  517. ->setMethods(array('getDownloaderForInstalledPackage', 'download'))
  518. ->getMock();
  519. $manager
  520. ->expects($this->once())
  521. ->method('getDownloaderForInstalledPackage')
  522. ->with($initial)
  523. ->will($this->returnValue($pearDownloader));
  524. $manager
  525. ->expects($this->once())
  526. ->method('download')
  527. ->with($target, 'vendor/bundles/FOS/UserBundle', false);
  528. $manager->update($initial, $target, 'vendor/bundles/FOS/UserBundle');
  529. }
  530. public function testUpdateSourceWithEqualTypes()
  531. {
  532. $initial = $this->createPackageMock();
  533. $initial
  534. ->expects($this->once())
  535. ->method('getInstallationSource')
  536. ->will($this->returnValue('source'));
  537. $initial
  538. ->expects($this->once())
  539. ->method('getSourceType')
  540. ->will($this->returnValue('svn'));
  541. $target = $this->createPackageMock();
  542. $target
  543. ->expects($this->once())
  544. ->method('getSourceType')
  545. ->will($this->returnValue('svn'));
  546. $svnDownloader = $this->createDownloaderMock();
  547. $svnDownloader
  548. ->expects($this->once())
  549. ->method('update')
  550. ->with($initial, $target, 'vendor/pkg');
  551. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  552. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  553. ->setMethods(array('getDownloaderForInstalledPackage', 'download'))
  554. ->getMock();
  555. $manager
  556. ->expects($this->once())
  557. ->method('getDownloaderForInstalledPackage')
  558. ->with($initial)
  559. ->will($this->returnValue($svnDownloader));
  560. $manager->update($initial, $target, 'vendor/pkg');
  561. }
  562. public function testUpdateSourceWithNotEqualTypes()
  563. {
  564. $initial = $this->createPackageMock();
  565. $initial
  566. ->expects($this->once())
  567. ->method('getInstallationSource')
  568. ->will($this->returnValue('source'));
  569. $initial
  570. ->expects($this->once())
  571. ->method('getSourceType')
  572. ->will($this->returnValue('svn'));
  573. $target = $this->createPackageMock();
  574. $target
  575. ->expects($this->once())
  576. ->method('getSourceType')
  577. ->will($this->returnValue('git'));
  578. $svnDownloader = $this->createDownloaderMock();
  579. $svnDownloader
  580. ->expects($this->once())
  581. ->method('remove')
  582. ->with($initial, 'vendor/pkg');
  583. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  584. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  585. ->setMethods(array('getDownloaderForInstalledPackage', 'download'))
  586. ->getMock();
  587. $manager
  588. ->expects($this->once())
  589. ->method('getDownloaderForInstalledPackage')
  590. ->with($initial)
  591. ->will($this->returnValue($svnDownloader));
  592. $manager
  593. ->expects($this->once())
  594. ->method('download')
  595. ->with($target, 'vendor/pkg', true);
  596. $manager->update($initial, $target, 'vendor/pkg');
  597. }
  598. public function testUpdateMetapackage()
  599. {
  600. $initial = $this->createPackageMock();
  601. $target = $this->createPackageMock();
  602. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  603. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  604. ->setMethods(array('getDownloaderForInstalledPackage'))
  605. ->getMock();
  606. $manager
  607. ->expects($this->once())
  608. ->method('getDownloaderForInstalledPackage')
  609. ->with($initial)
  610. ->will($this->returnValue(null)); // There is no downloader for metapackages.
  611. $manager->update($initial, $target, 'vendor/pkg');
  612. }
  613. public function testRemove()
  614. {
  615. $package = $this->createPackageMock();
  616. $pearDownloader = $this->createDownloaderMock();
  617. $pearDownloader
  618. ->expects($this->once())
  619. ->method('remove')
  620. ->with($package, 'vendor/bundles/FOS/UserBundle');
  621. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  622. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  623. ->setMethods(array('getDownloaderForInstalledPackage'))
  624. ->getMock();
  625. $manager
  626. ->expects($this->once())
  627. ->method('getDownloaderForInstalledPackage')
  628. ->with($package)
  629. ->will($this->returnValue($pearDownloader));
  630. $manager->remove($package, 'vendor/bundles/FOS/UserBundle');
  631. }
  632. public function testMetapackageRemove()
  633. {
  634. $package = $this->createPackageMock();
  635. $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  636. ->setConstructorArgs(array($this->io, false, $this->filesystem))
  637. ->setMethods(array('getDownloaderForInstalledPackage'))
  638. ->getMock();
  639. $manager
  640. ->expects($this->once())
  641. ->method('getDownloaderForInstalledPackage')
  642. ->with($package)
  643. ->will($this->returnValue(null)); // There is no downloader for metapackages.
  644. $manager->remove($package, 'vendor/bundles/FOS/UserBundle');
  645. }
  646. private function createDownloaderMock()
  647. {
  648. return $this->getMockBuilder('Composer\Downloader\DownloaderInterface')
  649. ->getMock();
  650. }
  651. private function createPackageMock()
  652. {
  653. return $this->getMockBuilder('Composer\Package\PackageInterface')
  654. ->getMock();
  655. }
  656. }