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