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\Installer\InstallerInstaller;
|
|
|
|
use Composer\Package\Loader\JsonLoader;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
|
|
|
|
class InstallerInstallerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2011-12-12 20:46:21 +00:00
|
|
|
$loader = new JsonLoader();
|
2011-11-05 22:51:35 +00:00
|
|
|
$this->packages = array();
|
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
|
$this->packages[] = $loader->load(__DIR__.'/Fixtures/installer-v'.$i.'/composer.json');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->im = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->repository = $this->getMockBuilder('Composer\Repository\WritableRepositoryInterface')
|
2012-01-17 22:13:35 +00:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')
|
2011-11-05 22:51:35 +00:00
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstallNewInstaller()
|
|
|
|
{
|
|
|
|
$this->repository
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getPackages')
|
|
|
|
->will($this->returnValue(array()));
|
2012-01-17 22:13:35 +00:00
|
|
|
$installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
|
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);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$installer->install($this->packages[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-17 22:13:35 +00:00
|
|
|
$installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
|
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);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$installer->update($this->packages[0], $this->packages[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-17 22:13:35 +00:00
|
|
|
$installer = new InstallerInstallerMock(__DIR__.'/Fixtures/', __DIR__.'/Fixtures/bin', $this->dm, $this->repository, $this->io, $this->im);
|
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);
|
|
|
|
}));
|
|
|
|
|
|
|
|
$installer->update($this->packages[1], $this->packages[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class InstallerInstallerMock extends InstallerInstaller
|
|
|
|
{
|
|
|
|
public function getInstallPath(PackageInterface $package)
|
|
|
|
{
|
|
|
|
$version = $package->getVersion();
|
|
|
|
return __DIR__.'/Fixtures/installer-v'.$version[0].'/';
|
|
|
|
}
|
|
|
|
}
|