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. use PHPUnit\Framework\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();
  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. $target = $this->createPackageMock();
  38. $this->repository
  39. ->expects($this->exactly(2))
  40. ->method('hasPackage')
  41. ->with($initial)
  42. ->will($this->onConsecutiveCalls(true, false));
  43. $this->repository
  44. ->expects($this->once())
  45. ->method('removePackage')
  46. ->with($initial);
  47. $this->repository
  48. ->expects($this->once())
  49. ->method('addPackage')
  50. ->with($target);
  51. $this->installer->update($this->repository, $initial, $target);
  52. $this->setExpectedException('InvalidArgumentException');
  53. $this->installer->update($this->repository, $initial, $target);
  54. }
  55. public function testUninstall()
  56. {
  57. $package = $this->createPackageMock();
  58. $this->repository
  59. ->expects($this->exactly(2))
  60. ->method('hasPackage')
  61. ->with($package)
  62. ->will($this->onConsecutiveCalls(true, false));
  63. $this->repository
  64. ->expects($this->once())
  65. ->method('removePackage')
  66. ->with($package);
  67. $this->installer->uninstall($this->repository, $package);
  68. $this->setExpectedException('InvalidArgumentException');
  69. $this->installer->uninstall($this->repository, $package);
  70. }
  71. private function createPackageMock()
  72. {
  73. return $this->getMockBuilder('Composer\Package\Package')
  74. ->setConstructorArgs(array(md5(mt_rand()), '1.0.0.0', '1.0.0'))
  75. ->getMock();
  76. }
  77. }