2011-11-05 22:51:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Installer;
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Config;
|
2013-08-13 11:25:21 +00:00
|
|
|
use Composer\Installer\PluginInstaller;
|
2015-06-02 01:21:06 +00:00
|
|
|
use Composer\Package\CompletePackage;
|
2011-11-05 22:51:35 +00:00
|
|
|
use Composer\Package\Loader\JsonLoader;
|
2012-07-18 15:20:01 +00:00
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2013-09-05 12:32:09 +00:00
|
|
|
use Composer\Plugin\PluginManager;
|
2013-01-06 19:34:52 +00:00
|
|
|
use Composer\Autoload\AutoloadGenerator;
|
2015-06-02 01:21:06 +00:00
|
|
|
use Composer\TestCase;
|
2013-09-20 03:39:35 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2011-11-05 22:51:35 +00:00
|
|
|
|
2015-06-02 01:21:06 +00:00
|
|
|
class PluginInstallerTest extends TestCase
|
2011-11-05 22:51:35 +00:00
|
|
|
{
|
2015-06-02 01:21:06 +00:00
|
|
|
/**
|
|
|
|
* @var Composer
|
|
|
|
*/
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $composer;
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PluginManager
|
|
|
|
*/
|
|
|
|
protected $pm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var AutoloadGenerator
|
|
|
|
*/
|
|
|
|
protected $autoloadGenerator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var CompletePackage[]
|
|
|
|
*/
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $packages;
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $directory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $im;
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $repository;
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $io;
|
|
|
|
|
2011-11-05 22:51:35 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2012-07-18 15:20:01 +00:00
|
|
|
$loader = new JsonLoader(new ArrayLoader());
|
2011-11-05 22:51:35 +00:00
|
|
|
$this->packages = array();
|
2013-09-20 03:39:35 +00:00
|
|
|
$this->directory = sys_get_temp_dir() . '/' . uniqid();
|
2015-06-02 01:21:06 +00:00
|
|
|
for ($i = 1; $i <= 7; $i++) {
|
2013-09-20 03:39:35 +00:00
|
|
|
$filename = '/Fixtures/plugin-v'.$i.'/composer.json';
|
2014-10-17 17:46:01 +00:00
|
|
|
mkdir(dirname($this->directory . $filename), 0777, true);
|
2013-09-20 03:39:35 +00:00
|
|
|
$this->packages[] = $loader->load(__DIR__ . $filename);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
2011-11-05 22:51:35 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2012-04-17 23:06:23 +00:00
|
|
|
$this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
|
2012-01-17 22:13:35 +00:00
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$rm = $this->getMockBuilder('Composer\Repository\RepositoryManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$rm->expects($this->any())
|
2013-03-03 16:18:50 +00:00
|
|
|
->method('getLocalRepository')
|
|
|
|
->will($this->returnValue($this->repository));
|
2012-06-24 18:11:06 +00:00
|
|
|
|
2013-09-12 11:28:17 +00:00
|
|
|
$im = $this->getMock('Composer\Installer\InstallationManager');
|
|
|
|
$im->expects($this->any())
|
|
|
|
->method('getInstallPath')
|
|
|
|
->will($this->returnCallback(function ($package) {
|
|
|
|
return __DIR__.'/Fixtures/'.$package->getPrettyName();
|
|
|
|
}));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$this->io = $this->getMock('Composer\IO\IOInterface');
|
2012-06-24 18:11:06 +00:00
|
|
|
|
2013-08-14 15:42:11 +00:00
|
|
|
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock();
|
2013-01-06 19:34:52 +00:00
|
|
|
$this->autoloadGenerator = new AutoloadGenerator($dispatcher);
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$this->composer = new Composer();
|
|
|
|
$config = new Config();
|
|
|
|
$this->composer->setConfig($config);
|
|
|
|
$this->composer->setDownloadManager($dm);
|
|
|
|
$this->composer->setRepositoryManager($rm);
|
2013-09-12 11:28:17 +00:00
|
|
|
$this->composer->setInstallationManager($im);
|
2013-01-06 19:34:52 +00:00
|
|
|
$this->composer->setAutoloadGenerator($this->autoloadGenerator);
|
2012-06-24 18:11:06 +00:00
|
|
|
|
2014-12-13 18:53:29 +00:00
|
|
|
$this->pm = new PluginManager($this->io, $this->composer);
|
2013-08-13 17:13:17 +00:00
|
|
|
$this->composer->setPluginManager($this->pm);
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$config->merge(array(
|
|
|
|
'config' => array(
|
2013-09-20 03:39:35 +00:00
|
|
|
'vendor-dir' => $this->directory.'/Fixtures/',
|
|
|
|
'home' => $this->directory.'/Fixtures',
|
|
|
|
'bin-dir' => $this->directory.'/Fixtures/bin',
|
2012-06-24 18:11:06 +00:00
|
|
|
),
|
|
|
|
));
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 17:41:54 +00:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
2013-09-20 03:39:35 +00:00
|
|
|
$filesystem = new Filesystem();
|
2013-09-20 04:31:06 +00:00
|
|
|
$filesystem->removeDirectory($this->directory);
|
2013-09-20 03:39:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 13:55:52 +00:00
|
|
|
public function testInstallNewPlugin()
|
2011-11-05 22:51:35 +00:00
|
|
|
{
|
|
|
|
$this->repository
|
2013-08-15 14:58:48 +00:00
|
|
|
->expects($this->exactly(2))
|
2011-11-05 22:51:35 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
2013-08-13 17:13:17 +00:00
|
|
|
$installer = new PluginInstaller($this->io, $this->composer);
|
|
|
|
$this->pm->loadInstalledPlugins();
|
2011-11-05 22:51:35 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$installer->install($this->repository, $this->packages[0]);
|
2013-08-13 17:13:17 +00:00
|
|
|
|
|
|
|
$plugins = $this->pm->getPlugins();
|
|
|
|
$this->assertEquals('installer-v1', $plugins[0]->version);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 13:55:52 +00:00
|
|
|
public function testInstallMultiplePlugins()
|
2012-05-25 08:28:53 +00:00
|
|
|
{
|
|
|
|
$this->repository
|
2013-08-15 14:58:48 +00:00
|
|
|
->expects($this->exactly(2))
|
2012-05-25 08:28:53 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
2013-08-13 17:13:17 +00:00
|
|
|
$installer = new PluginInstaller($this->io, $this->composer);
|
|
|
|
$this->pm->loadInstalledPlugins();
|
2012-05-25 08:28:53 +00:00
|
|
|
|
|
|
|
$installer->install($this->repository, $this->packages[3]);
|
2013-08-13 17:13:17 +00:00
|
|
|
|
|
|
|
$plugins = $this->pm->getPlugins();
|
|
|
|
$this->assertEquals('plugin1', $plugins[0]->name);
|
|
|
|
$this->assertEquals('installer-v4', $plugins[0]->version);
|
|
|
|
$this->assertEquals('plugin2', $plugins[1]->name);
|
|
|
|
$this->assertEquals('installer-v4', $plugins[1]->version);
|
2012-05-25 08:28:53 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 22:51:35 +00:00
|
|
|
public function testUpgradeWithNewClassName()
|
|
|
|
{
|
|
|
|
$this->repository
|
2013-08-15 14:58:48 +00:00
|
|
|
->expects($this->exactly(3))
|
2011-11-05 22:51:35 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array($this->packages[0])));
|
|
|
|
$this->repository
|
2012-02-18 22:21:45 +00:00
|
|
|
->expects($this->exactly(2))
|
2011-11-05 22:51:35 +00:00
|
|
|
->method('hasPackage')
|
2012-02-18 22:21:45 +00:00
|
|
|
->will($this->onConsecutiveCalls(true, false));
|
2013-08-13 17:13:17 +00:00
|
|
|
$installer = new PluginInstaller($this->io, $this->composer);
|
|
|
|
$this->pm->loadInstalledPlugins();
|
2011-11-05 22:51:35 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$installer->update($this->repository, $this->packages[0], $this->packages[1]);
|
2013-08-13 17:13:17 +00:00
|
|
|
|
|
|
|
$plugins = $this->pm->getPlugins();
|
|
|
|
$this->assertEquals('installer-v2', $plugins[1]->version);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpgradeWithSameClassName()
|
|
|
|
{
|
|
|
|
$this->repository
|
2013-08-15 14:58:48 +00:00
|
|
|
->expects($this->exactly(3))
|
2011-11-05 22:51:35 +00:00
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array($this->packages[1])));
|
|
|
|
$this->repository
|
2012-02-18 22:21:45 +00:00
|
|
|
->expects($this->exactly(2))
|
2011-11-05 22:51:35 +00:00
|
|
|
->method('hasPackage')
|
2012-02-18 22:21:45 +00:00
|
|
|
->will($this->onConsecutiveCalls(true, false));
|
2013-08-13 17:13:17 +00:00
|
|
|
$installer = new PluginInstaller($this->io, $this->composer);
|
|
|
|
$this->pm->loadInstalledPlugins();
|
2011-11-05 22:51:35 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$installer->update($this->repository, $this->packages[1], $this->packages[2]);
|
2011-11-05 22:51:35 +00:00
|
|
|
|
2013-08-13 17:13:17 +00:00
|
|
|
$plugins = $this->pm->getPlugins();
|
|
|
|
$this->assertEquals('installer-v3', $plugins[1]->version);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
2014-07-21 13:07:27 +00:00
|
|
|
|
|
|
|
public function testRegisterPluginOnlyOneTime()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
$installer = new PluginInstaller($this->io, $this->composer);
|
|
|
|
$this->pm->loadInstalledPlugins();
|
|
|
|
|
|
|
|
$installer->install($this->repository, $this->packages[0]);
|
|
|
|
$installer->install($this->repository, clone $this->packages[0]);
|
|
|
|
|
|
|
|
$plugins = $this->pm->getPlugins();
|
|
|
|
$this->assertCount(1, $plugins);
|
|
|
|
$this->assertEquals('installer-v1', $plugins[0]->version);
|
|
|
|
}
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $newPluginApiVersion
|
|
|
|
* @param CompletePackage[] $plugins
|
|
|
|
*/
|
|
|
|
private function setPluginApiVersionWithPlugins($newPluginApiVersion, array $plugins = array())
|
|
|
|
{
|
|
|
|
// reset the plugin manager's installed plugins
|
2015-06-02 16:39:02 +00:00
|
|
|
$this->pm = $this->getMockBuilder('Composer\Plugin\PluginManager')
|
|
|
|
->setMethods(array('getPluginApiVersion'))
|
|
|
|
->setConstructorArgs(array($this->io, $this->composer))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
// mock the Plugin API version
|
|
|
|
$this->pm->expects($this->any())
|
|
|
|
->method('getPluginApiVersion')
|
|
|
|
->will($this->returnValue($newPluginApiVersion));
|
2015-06-02 01:21:06 +00:00
|
|
|
|
|
|
|
$plugApiInternalPackage = $this->getPackage(
|
|
|
|
'composer-plugin-api',
|
|
|
|
$newPluginApiVersion,
|
|
|
|
'Composer\Package\CompletePackage'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Add the plugins to the repo along with the internal Plugin package on which they all rely.
|
|
|
|
$this->repository
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnCallback(function() use($plugApiInternalPackage, $plugins) {
|
|
|
|
return array_merge(array($plugApiInternalPackage), $plugins);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$this->pm->loadInstalledPlugins();
|
|
|
|
}
|
|
|
|
|
2015-06-08 21:45:20 +00:00
|
|
|
public function testExactPluginVersionStyleAreRegisteredCorrectly()
|
2015-06-02 01:21:06 +00:00
|
|
|
{
|
2015-06-08 21:45:20 +00:00
|
|
|
$pluginsWithFixedAPIVersions = array(
|
2015-06-02 01:21:06 +00:00
|
|
|
$this->packages[0],
|
|
|
|
$this->packages[1],
|
|
|
|
$this->packages[2],
|
|
|
|
);
|
|
|
|
|
2015-06-08 21:45:20 +00:00
|
|
|
$this->setPluginApiVersionWithPlugins('1.0.0', $pluginsWithFixedAPIVersions);
|
2015-06-02 01:21:06 +00:00
|
|
|
$this->assertCount(3, $this->pm->getPlugins());
|
|
|
|
|
2015-06-08 21:45:20 +00:00
|
|
|
$this->setPluginApiVersionWithPlugins('1.0.1', $pluginsWithFixedAPIVersions);
|
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
2015-06-02 01:21:06 +00:00
|
|
|
|
2015-06-08 21:45:20 +00:00
|
|
|
$this->setPluginApiVersionWithPlugins('2.0.0-dev', $pluginsWithFixedAPIVersions);
|
2015-06-02 01:21:06 +00:00
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStarPluginVersionWorksWithAnyAPIVersion()
|
|
|
|
{
|
|
|
|
$starVersionPlugin = array($this->packages[4]);
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.0.0', $starVersionPlugin);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.9.9', $starVersionPlugin);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('2.0.0-dev', $starVersionPlugin);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('100.0.0-stable', $starVersionPlugin);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPluginConstraintWorksOnlyWithCertainAPIVersion()
|
|
|
|
{
|
|
|
|
$pluginWithApiConstraint = array($this->packages[5]);
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.0.0', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.1.9', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.2.0', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.9.9', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPluginRangeConstraintsWorkOnlyWithCertainAPIVersion()
|
|
|
|
{
|
|
|
|
$pluginWithApiConstraint = array($this->packages[6]);
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('1.0.0', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('3.0.0', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(1, $this->pm->getPlugins());
|
|
|
|
|
|
|
|
$this->setPluginApiVersionWithPlugins('5.5.0', $pluginWithApiConstraint);
|
|
|
|
$this->assertCount(0, $this->pm->getPlugins());
|
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|