MetapackageInstallerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\Installer;
  12. use Composer\Installer\MetapackageInstaller;
  13. class MetapackageInstallerTest extends \PHPUnit_Framework_TestCase
  14. {
  15. private $repository;
  16. private $installer;
  17. private $io;
  18. protected function setUp()
  19. {
  20. $this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
  21. $this->io = $this->getMock('Composer\IO\IOInterface');
  22. $this->installer = new MetapackageInstaller();
  23. }
  24. public function testInstall()
  25. {
  26. $package = $this->createPackageMock();
  27. $this->repository
  28. ->expects($this->once())
  29. ->method('addPackage')
  30. ->with($package);
  31. $this->installer->install($this->repository, $package);
  32. }
  33. public function testUpdate()
  34. {
  35. $initial = $this->createPackageMock();
  36. $target = $this->createPackageMock();
  37. $this->repository
  38. ->expects($this->exactly(2))
  39. ->method('hasPackage')
  40. ->with($initial)
  41. ->will($this->onConsecutiveCalls(true, false));
  42. $this->repository
  43. ->expects($this->once())
  44. ->method('removePackage')
  45. ->with($initial);
  46. $this->repository
  47. ->expects($this->once())
  48. ->method('addPackage')
  49. ->with($target);
  50. $this->installer->update($this->repository, $initial, $target);
  51. $this->setExpectedException('InvalidArgumentException');
  52. $this->installer->update($this->repository, $initial, $target);
  53. }
  54. public function testUninstall()
  55. {
  56. $package = $this->createPackageMock();
  57. $this->repository
  58. ->expects($this->exactly(2))
  59. ->method('hasPackage')
  60. ->with($package)
  61. ->will($this->onConsecutiveCalls(true, false));
  62. $this->repository
  63. ->expects($this->once())
  64. ->method('removePackage')
  65. ->with($package);
  66. $this->installer->uninstall($this->repository, $package);
  67. // TODO re-enable once #125 is fixed and we throw exceptions again
  68. // $this->setExpectedException('InvalidArgumentException');
  69. $this->installer->uninstall($this->repository, $package);
  70. }
  71. private function createPackageMock()
  72. {
  73. return $this->getMockBuilder('Composer\Package\MemoryPackage')
  74. ->setConstructorArgs(array(md5(rand()), '1.0.0.0', '1.0.0'))
  75. ->getMock();
  76. }
  77. }