MetapackageInstallerTest.php 2.9 KB

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