InstallerInstallerTest.php 4.0 KB

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