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;
|
2011-11-05 22:51:35 +00:00
|
|
|
use Composer\Installer\InstallerInstaller;
|
|
|
|
use Composer\Package\Loader\JsonLoader;
|
2012-07-18 15:20:01 +00:00
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2011-11-05 22:51:35 +00:00
|
|
|
use Composer\Package\PackageInterface;
|
2013-01-06 19:34:52 +00:00
|
|
|
use Composer\Autoload\AutoloadGenerator;
|
2011-11-05 22:51:35 +00:00
|
|
|
|
|
|
|
class InstallerInstallerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
protected $composer;
|
|
|
|
protected $packages;
|
|
|
|
protected $im;
|
|
|
|
protected $repository;
|
|
|
|
protected $io;
|
2013-01-06 19:34:52 +00:00
|
|
|
protected $autoloadGenerator;
|
2012-06-24 18:11:06 +00:00
|
|
|
|
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();
|
2012-05-25 08:28:53 +00:00
|
|
|
for ($i = 1; $i <= 4; $i++) {
|
2011-11-05 22:51:35 +00:00
|
|
|
$this->packages[] = $loader->load(__DIR__.'/Fixtures/installer-v'.$i.'/composer.json');
|
|
|
|
}
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
2011-11-05 22:51:35 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
|
|
|
->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())
|
|
|
|
->method('getLocalRepositories')
|
|
|
|
->will($this->returnValue(array($this->repository)));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$this->io = $this->getMock('Composer\IO\IOInterface');
|
2012-06-24 18:11:06 +00:00
|
|
|
|
2013-01-06 19:34:52 +00:00
|
|
|
$dispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock();
|
|
|
|
$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->setInstallationManager($this->im);
|
|
|
|
$this->composer->setRepositoryManager($rm);
|
2013-01-06 19:34:52 +00:00
|
|
|
$this->composer->setAutoloadGenerator($this->autoloadGenerator);
|
2012-06-24 18:11:06 +00:00
|
|
|
|
|
|
|
$config->merge(array(
|
|
|
|
'config' => array(
|
|
|
|
'vendor-dir' => __DIR__.'/Fixtures/',
|
|
|
|
'bin-dir' => __DIR__.'/Fixtures/bin',
|
|
|
|
),
|
|
|
|
));
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstallNewInstaller()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
2012-06-24 18:11:06 +00:00
|
|
|
$installer = new InstallerInstallerMock($this->io, $this->composer);
|
2011-11-05 22:51:35 +00:00
|
|
|
|
|
|
|
$test = $this;
|
|
|
|
$this->im
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addInstaller')
|
|
|
|
->will($this->returnCallback(function ($installer) use ($test) {
|
|
|
|
$test->assertEquals('installer-v1', $installer->version);
|
|
|
|
}));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$installer->install($this->repository, $this->packages[0]);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 08:28:53 +00:00
|
|
|
public function testInstallMultipleInstallers()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$installer = new InstallerInstallerMock($this->io, $this->composer);
|
2012-05-25 08:28:53 +00:00
|
|
|
|
|
|
|
$test = $this;
|
|
|
|
|
|
|
|
$this->im
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('addInstaller')
|
|
|
|
->will($this->returnCallback(function ($installer) use ($test) {
|
|
|
|
$test->assertEquals('custom1', $installer->name);
|
|
|
|
$test->assertEquals('installer-v4', $installer->version);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$this->im
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('addInstaller')
|
|
|
|
->will($this->returnCallback(function ($installer) use ($test) {
|
|
|
|
$test->assertEquals('custom2', $installer->name);
|
|
|
|
$test->assertEquals('installer-v4', $installer->version);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$installer->install($this->repository, $this->packages[3]);
|
|
|
|
}
|
|
|
|
|
2011-11-05 22:51:35 +00:00
|
|
|
public function testUpgradeWithNewClassName()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->once())
|
|
|
|
->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));
|
2012-06-24 18:11:06 +00:00
|
|
|
$installer = new InstallerInstallerMock($this->io, $this->composer);
|
2011-11-05 22:51:35 +00:00
|
|
|
|
|
|
|
$test = $this;
|
|
|
|
$this->im
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addInstaller')
|
|
|
|
->will($this->returnCallback(function ($installer) use ($test) {
|
|
|
|
$test->assertEquals('installer-v2', $installer->version);
|
|
|
|
}));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$installer->update($this->repository, $this->packages[0], $this->packages[1]);
|
2011-11-05 22:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpgradeWithSameClassName()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->once())
|
|
|
|
->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));
|
2012-06-24 18:11:06 +00:00
|
|
|
$installer = new InstallerInstallerMock($this->io, $this->composer);
|
2011-11-05 22:51:35 +00:00
|
|
|
|
|
|
|
$test = $this;
|
|
|
|
$this->im
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addInstaller')
|
|
|
|
->will($this->returnCallback(function ($installer) use ($test) {
|
|
|
|
$test->assertEquals('installer-v3', $installer->version);
|
|
|
|
}));
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class InstallerInstallerMock extends InstallerInstaller
|
|
|
|
{
|
|
|
|
public function getInstallPath(PackageInterface $package)
|
|
|
|
{
|
|
|
|
$version = $package->getVersion();
|
2012-06-14 10:10:01 +00:00
|
|
|
|
2011-11-05 22:51:35 +00:00
|
|
|
return __DIR__.'/Fixtures/installer-v'.$version[0].'/';
|
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|