InstallerInstallerTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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->getMock('Composer\Repository\InstalledRepositoryInterface');
  31. $this->io = $this->getMock('Composer\IO\IOInterface');
  32. }
  33. public function testInstallNewInstaller()
  34. {
  35. $this->repository
  36. ->expects($this->once())
  37. ->method('getPackages')
  38. ->will($this->returnValue(array()));
  39. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->io, $this->im, array($this->repository));
  40. $test = $this;
  41. $this->im
  42. ->expects($this->once())
  43. ->method('addInstaller')
  44. ->will($this->returnCallback(function ($installer) use ($test) {
  45. $test->assertEquals('installer-v1', $installer->version);
  46. }));
  47. $installer->install($this->repository, $this->packages[0]);
  48. }
  49. public function testUpgradeWithNewClassName()
  50. {
  51. $this->repository
  52. ->expects($this->once())
  53. ->method('getPackages')
  54. ->will($this->returnValue(array($this->packages[0])));
  55. $this->repository
  56. ->expects($this->exactly(2))
  57. ->method('hasPackage')
  58. ->will($this->onConsecutiveCalls(true, false));
  59. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->io, $this->im, array($this->repository));
  60. $test = $this;
  61. $this->im
  62. ->expects($this->once())
  63. ->method('addInstaller')
  64. ->will($this->returnCallback(function ($installer) use ($test) {
  65. $test->assertEquals('installer-v2', $installer->version);
  66. }));
  67. $installer->update($this->repository, $this->packages[0], $this->packages[1]);
  68. }
  69. public function testUpgradeWithSameClassName()
  70. {
  71. $this->repository
  72. ->expects($this->once())
  73. ->method('getPackages')
  74. ->will($this->returnValue(array($this->packages[1])));
  75. $this->repository
  76. ->expects($this->exactly(2))
  77. ->method('hasPackage')
  78. ->will($this->onConsecutiveCalls(true, false));
  79. $installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->io, $this->im, array($this->repository));
  80. $test = $this;
  81. $this->im
  82. ->expects($this->once())
  83. ->method('addInstaller')
  84. ->will($this->returnCallback(function ($installer) use ($test) {
  85. $test->assertEquals('installer-v3', $installer->version);
  86. }));
  87. $installer->update($this->repository, $this->packages[1], $this->packages[2]);
  88. }
  89. }
  90. class InstallerInstallerMock extends InstallerInstaller
  91. {
  92. public function getInstallPath(PackageInterface $package)
  93. {
  94. $version = $package->getVersion();
  95. return __DIR__.'/Fixtures/installer-v'.$version[0].'/';
  96. }
  97. }