1
0
Fork 0
composer/tests/Composer/Test/Plugin/PluginInstallerTest.php

151 lines
5.0 KiB
PHP
Raw Normal View History

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;
use Composer\Composer;
use Composer\Config;
use Composer\Installer\PluginInstaller;
2011-11-05 22:51:35 +00:00
use Composer\Package\Loader\JsonLoader;
use Composer\Package\Loader\ArrayLoader;
2011-11-05 22:51:35 +00:00
use Composer\Package\PackageInterface;
2013-09-05 12:32:09 +00:00
use Composer\Plugin\PluginManager;
2013-01-06 19:34:52 +00:00
use Composer\Autoload\AutoloadGenerator;
2011-11-05 22:51:35 +00:00
class PluginInstallerTest extends \PHPUnit_Framework_TestCase
2011-11-05 22:51:35 +00:00
{
protected $composer;
protected $packages;
protected $im;
protected $pm;
protected $repository;
protected $io;
2013-01-06 19:34:52 +00:00
protected $autoloadGenerator;
2011-11-05 22:51:35 +00:00
protected function setUp()
{
$loader = new JsonLoader(new ArrayLoader());
2011-11-05 22:51:35 +00:00
$this->packages = array();
for ($i = 1; $i <= 4; $i++) {
$this->packages[] = $loader->load(__DIR__.'/Fixtures/plugin-v'.$i.'/composer.json');
2011-11-05 22:51:35 +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
$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-04-14 13:45:25 +00:00
$this->io = $this->getMock('Composer\IO\IOInterface');
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock();
2013-01-06 19:34:52 +00:00
$this->autoloadGenerator = new AutoloadGenerator($dispatcher);
$this->composer = new Composer();
$config = new Config();
$this->composer->setConfig($config);
$this->composer->setDownloadManager($dm);
$this->composer->setRepositoryManager($rm);
2013-01-06 19:34:52 +00:00
$this->composer->setAutoloadGenerator($this->autoloadGenerator);
2013-09-05 12:32:09 +00:00
$this->pm = new PluginManager($this->composer, $this->io);
$this->composer->setPluginManager($this->pm);
$config->merge(array(
'config' => array(
'vendor-dir' => __DIR__.'/Fixtures/',
'home' => __DIR__.'/Fixtures',
'bin-dir' => __DIR__.'/Fixtures/bin',
),
));
2011-11-05 22:51:35 +00:00
}
public function testInstallNewPlugin()
2011-11-05 22:51:35 +00:00
{
$this->repository
->expects($this->exactly(2))
2011-11-05 22:51:35 +00:00
->method('getPackages')
->will($this->returnValue(array()));
$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]);
$plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v1', $plugins[0]->version);
2011-11-05 22:51:35 +00:00
}
public function testInstallMultiplePlugins()
{
$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[3]);
$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);
}
2011-11-05 22:51:35 +00:00
public function testUpgradeWithNewClassName()
{
$this->repository
->expects($this->exactly(3))
2011-11-05 22:51:35 +00:00
->method('getPackages')
->will($this->returnValue(array($this->packages[0])));
$this->repository
->expects($this->exactly(2))
2011-11-05 22:51:35 +00:00
->method('hasPackage')
->will($this->onConsecutiveCalls(true, false));
$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]);
$plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v2', $plugins[1]->version);
2011-11-05 22:51:35 +00:00
}
public function testUpgradeWithSameClassName()
{
$this->repository
->expects($this->exactly(3))
2011-11-05 22:51:35 +00:00
->method('getPackages')
->will($this->returnValue(array($this->packages[1])));
$this->repository
->expects($this->exactly(2))
2011-11-05 22:51:35 +00:00
->method('hasPackage')
->will($this->onConsecutiveCalls(true, false));
$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
$plugins = $this->pm->getPlugins();
$this->assertEquals('installer-v3', $plugins[1]->version);
2011-11-05 22:51:35 +00:00
}
2012-06-14 10:10:01 +00:00
}