InstallerInstallerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\InstallerInstaller;
  13. use Composer\Package\Loader\JsonLoader;
  14. use Composer\Package\PackageInterface;
  15. class InstallerInstallerTest extends \PHPUnit_Framework_TestCase
  16. {
  17. protected function setUp()
  18. {
  19. $loader = new JsonLoader();
  20. $this->packages = array();
  21. for ($i = 1; $i <= 3; $i++) {
  22. $this->packages[] = $loader->load(__DIR__.'/Fixtures/installer-v'.$i.'/composer.json');
  23. }
  24. $this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->repository = $this->getMockBuilder('Composer\Repository\WritableRepositoryInterface')
  31. ->getMock();
  32. $this->io = $this->getMockBuilder('Composer\IO\IOInterface')
  33. ->getMock();
  34. }
  35. public function testInstallNewInstaller()
  36. {
  37. $this->repository
  38. ->expects($this->once())
  39. ->method('getPackages')
  40. ->will($this->returnValue(array()));
  41. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
  42. $test = $this;
  43. $this->im
  44. ->expects($this->once())
  45. ->method('addInstaller')
  46. ->will($this->returnCallback(function ($installer) use ($test) {
  47. $test->assertEquals('installer-v1', $installer->version);
  48. }));
  49. $installer->install($this->packages[0]);
  50. }
  51. public function testUpgradeWithNewClassName()
  52. {
  53. $this->repository
  54. ->expects($this->once())
  55. ->method('getPackages')
  56. ->will($this->returnValue(array($this->packages[0])));
  57. $this->repository
  58. ->expects($this->exactly(2))
  59. ->method('hasPackage')
  60. ->will($this->onConsecutiveCalls(true, false));
  61. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
  62. $test = $this;
  63. $this->im
  64. ->expects($this->once())
  65. ->method('addInstaller')
  66. ->will($this->returnCallback(function ($installer) use ($test) {
  67. $test->assertEquals('installer-v2', $installer->version);
  68. }));
  69. $installer->update($this->packages[0], $this->packages[1]);
  70. }
  71. public function testUpgradeWithSameClassName()
  72. {
  73. $this->repository
  74. ->expects($this->once())
  75. ->method('getPackages')
  76. ->will($this->returnValue(array($this->packages[1])));
  77. $this->repository
  78. ->expects($this->exactly(2))
  79. ->method('hasPackage')
  80. ->will($this->onConsecutiveCalls(true, false));
  81. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
  82. $test = $this;
  83. $this->im
  84. ->expects($this->once())
  85. ->method('addInstaller')
  86. ->will($this->returnCallback(function ($installer) use ($test) {
  87. $test->assertEquals('installer-v3', $installer->version);
  88. }));
  89. $installer->update($this->packages[1], $this->packages[2]);
  90. }
  91. }
  92. class InstallerInstallerMock extends InstallerInstaller
  93. {
  94. public function getInstallPath(PackageInterface $package)
  95. {
  96. $version = $package->getVersion();
  97. return __DIR__.'/Fixtures/installer-v'.$version[0].'/';
  98. }
  99. }