PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/composer/composer/tests/Composer/Test/Plugin/PluginInstallerTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 184 lines | 145 code | 30 blank | 9 comment | 1 complexity | 7f80e42f0771d49665687e807958db9f MD5 | raw file
  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\Composer;
  13. use Composer\Config;
  14. use Composer\Installer\PluginInstaller;
  15. use Composer\Package\Loader\JsonLoader;
  16. use Composer\Package\Loader\ArrayLoader;
  17. use Composer\Plugin\PluginManager;
  18. use Composer\Autoload\AutoloadGenerator;
  19. use Composer\Util\Filesystem;
  20. class PluginInstallerTest extends \PHPUnit_Framework_TestCase
  21. {
  22. protected $composer;
  23. protected $packages;
  24. protected $im;
  25. protected $pm;
  26. protected $repository;
  27. protected $io;
  28. protected $autoloadGenerator;
  29. protected $directory;
  30. protected function setUp()
  31. {
  32. $loader = new JsonLoader(new ArrayLoader());
  33. $this->packages = array();
  34. $this->directory = sys_get_temp_dir() . '/' . uniqid();
  35. for ($i = 1; $i <= 4; $i++) {
  36. $filename = '/Fixtures/plugin-v'.$i.'/composer.json';
  37. mkdir(dirname($this->directory . $filename), 0777, true);
  38. $this->packages[] = $loader->load(__DIR__ . $filename);
  39. }
  40. $dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
  41. ->disableOriginalConstructor()
  42. ->getMock();
  43. $this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
  44. $rm = $this->getMockBuilder('Composer\Repository\RepositoryManager')
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $rm->expects($this->any())
  48. ->method('getLocalRepository')
  49. ->will($this->returnValue($this->repository));
  50. $im = $this->getMock('Composer\Installer\InstallationManager');
  51. $im->expects($this->any())
  52. ->method('getInstallPath')
  53. ->will($this->returnCallback(function ($package) {
  54. return __DIR__.'/Fixtures/'.$package->getPrettyName();
  55. }));
  56. $this->io = $this->getMock('Composer\IO\IOInterface');
  57. $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock();
  58. $this->autoloadGenerator = new AutoloadGenerator($dispatcher);
  59. $this->composer = new Composer();
  60. $config = new Config();
  61. $this->composer->setConfig($config);
  62. $this->composer->setDownloadManager($dm);
  63. $this->composer->setRepositoryManager($rm);
  64. $this->composer->setInstallationManager($im);
  65. $this->composer->setAutoloadGenerator($this->autoloadGenerator);
  66. $this->pm = new PluginManager($this->io, $this->composer);
  67. $this->composer->setPluginManager($this->pm);
  68. $config->merge(array(
  69. 'config' => array(
  70. 'vendor-dir' => $this->directory.'/Fixtures/',
  71. 'home' => $this->directory.'/Fixtures',
  72. 'bin-dir' => $this->directory.'/Fixtures/bin',
  73. ),
  74. ));
  75. }
  76. protected function tearDown()
  77. {
  78. $filesystem = new Filesystem();
  79. $filesystem->removeDirectory($this->directory);
  80. }
  81. public function testInstallNewPlugin()
  82. {
  83. $this->repository
  84. ->expects($this->exactly(2))
  85. ->method('getPackages')
  86. ->will($this->returnValue(array()));
  87. $installer = new PluginInstaller($this->io, $this->composer);
  88. $this->pm->loadInstalledPlugins();
  89. $installer->install($this->repository, $this->packages[0]);
  90. $plugins = $this->pm->getPlugins();
  91. $this->assertEquals('installer-v1', $plugins[0]->version);
  92. }
  93. public function testInstallMultiplePlugins()
  94. {
  95. $this->repository
  96. ->expects($this->exactly(2))
  97. ->method('getPackages')
  98. ->will($this->returnValue(array()));
  99. $installer = new PluginInstaller($this->io, $this->composer);
  100. $this->pm->loadInstalledPlugins();
  101. $installer->install($this->repository, $this->packages[3]);
  102. $plugins = $this->pm->getPlugins();
  103. $this->assertEquals('plugin1', $plugins[0]->name);
  104. $this->assertEquals('installer-v4', $plugins[0]->version);
  105. $this->assertEquals('plugin2', $plugins[1]->name);
  106. $this->assertEquals('installer-v4', $plugins[1]->version);
  107. }
  108. public function testUpgradeWithNewClassName()
  109. {
  110. $this->repository
  111. ->expects($this->exactly(3))
  112. ->method('getPackages')
  113. ->will($this->returnValue(array($this->packages[0])));
  114. $this->repository
  115. ->expects($this->exactly(2))
  116. ->method('hasPackage')
  117. ->will($this->onConsecutiveCalls(true, false));
  118. $installer = new PluginInstaller($this->io, $this->composer);
  119. $this->pm->loadInstalledPlugins();
  120. $installer->update($this->repository, $this->packages[0], $this->packages[1]);
  121. $plugins = $this->pm->getPlugins();
  122. $this->assertEquals('installer-v2', $plugins[1]->version);
  123. }
  124. public function testUpgradeWithSameClassName()
  125. {
  126. $this->repository
  127. ->expects($this->exactly(3))
  128. ->method('getPackages')
  129. ->will($this->returnValue(array($this->packages[1])));
  130. $this->repository
  131. ->expects($this->exactly(2))
  132. ->method('hasPackage')
  133. ->will($this->onConsecutiveCalls(true, false));
  134. $installer = new PluginInstaller($this->io, $this->composer);
  135. $this->pm->loadInstalledPlugins();
  136. $installer->update($this->repository, $this->packages[1], $this->packages[2]);
  137. $plugins = $this->pm->getPlugins();
  138. $this->assertEquals('installer-v3', $plugins[1]->version);
  139. }
  140. public function testRegisterPluginOnlyOneTime()
  141. {
  142. $this->repository
  143. ->expects($this->exactly(2))
  144. ->method('getPackages')
  145. ->will($this->returnValue(array()));
  146. $installer = new PluginInstaller($this->io, $this->composer);
  147. $this->pm->loadInstalledPlugins();
  148. $installer->install($this->repository, $this->packages[0]);
  149. $installer->install($this->repository, clone $this->packages[0]);
  150. $plugins = $this->pm->getPlugins();
  151. $this->assertCount(1, $plugins);
  152. $this->assertEquals('installer-v1', $plugins[0]->version);
  153. }
  154. }