2011-09-23 21:23:16 +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\LibraryInstaller;
|
2012-02-09 17:45:28 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2012-06-24 18:11:06 +00:00
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Config;
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
class LibraryInstallerTest extends TestCase
|
2011-09-23 21:23:16 +00:00
|
|
|
{
|
2012-08-16 09:22:30 +00:00
|
|
|
protected $composer;
|
|
|
|
protected $config;
|
|
|
|
protected $vendorDir;
|
|
|
|
protected $binDir;
|
|
|
|
protected $dm;
|
|
|
|
protected $repository;
|
|
|
|
protected $io;
|
|
|
|
protected $fs;
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->fs = new Filesystem;
|
2011-12-03 14:39:06 +00:00
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$this->composer = new Composer();
|
|
|
|
$this->config = new Config();
|
|
|
|
$this->composer->setConfig($this->config);
|
|
|
|
|
2011-12-21 15:46:23 +00:00
|
|
|
$this->vendorDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-vendor';
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->ensureDirectoryExistsAndClear($this->vendorDir);
|
2011-12-03 14:39:06 +00:00
|
|
|
|
2011-12-21 15:46:23 +00:00
|
|
|
$this->binDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-bin';
|
2012-02-24 11:28:41 +00:00
|
|
|
$this->ensureDirectoryExistsAndClear($this->binDir);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
$this->config->merge(array(
|
|
|
|
'config' => array(
|
|
|
|
'vendor-dir' => $this->vendorDir,
|
|
|
|
'bin-dir' => $this->binDir,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
2011-09-23 21:23:16 +00:00
|
|
|
$this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2012-06-24 18:11:06 +00:00
|
|
|
$this->composer->setDownloadManager($this->dm);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-04-17 23:06:23 +00:00
|
|
|
$this->repository = $this->getMock('Composer\Repository\InstalledRepositoryInterface');
|
2012-04-14 13:45:25 +00:00
|
|
|
$this->io = $this->getMock('Composer\IO\IOInterface');
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 11:28:41 +00:00
|
|
|
protected function tearDown()
|
|
|
|
{
|
2012-03-07 23:11:52 +00:00
|
|
|
$this->fs->removeDirectory($this->vendorDir);
|
|
|
|
$this->fs->removeDirectory($this->binDir);
|
2012-02-24 09:40:47 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:43:12 +00:00
|
|
|
public function testInstallerCreationShouldNotCreateVendorDirectory()
|
2011-09-23 21:23:16 +00:00
|
|
|
{
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->fs->removeDirectory($this->vendorDir);
|
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
new LibraryInstaller($this->io, $this->composer);
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->assertFileNotExists($this->vendorDir);
|
|
|
|
}
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-02-16 20:43:12 +00:00
|
|
|
public function testInstallerCreationShouldNotCreateBinDirectory()
|
|
|
|
{
|
|
|
|
$this->fs->removeDirectory($this->binDir);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-06-24 18:11:06 +00:00
|
|
|
new LibraryInstaller($this->io, $this->composer);
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->assertFileNotExists($this->binDir);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalled()
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer);
|
2011-09-23 21:23:16 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->exactly(2))
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('hasPackage')
|
2011-09-23 21:23:16 +00:00
|
|
|
->with($package)
|
|
|
|
->will($this->onConsecutiveCalls(true, false));
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$this->assertTrue($library->isInstalled($this->repository, $package));
|
|
|
|
$this->assertFalse($library->isInstalled($this->repository, $package));
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:43:12 +00:00
|
|
|
/**
|
|
|
|
* @depends testInstallerCreationShouldNotCreateVendorDirectory
|
|
|
|
* @depends testInstallerCreationShouldNotCreateBinDirectory
|
|
|
|
*/
|
2011-09-23 21:23:16 +00:00
|
|
|
public function testInstall()
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer);
|
2011-09-23 21:23:16 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$package
|
2012-06-27 05:27:01 +00:00
|
|
|
->expects($this->any())
|
2011-12-15 14:14:33 +00:00
|
|
|
->method('getPrettyName')
|
2011-09-23 22:30:17 +00:00
|
|
|
->will($this->returnValue('some/package'));
|
|
|
|
|
2011-09-23 21:23:16 +00:00
|
|
|
$this->dm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('download')
|
2011-12-03 14:39:06 +00:00
|
|
|
->with($package, $this->vendorDir.'/some/package');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->once())
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('addPackage')
|
|
|
|
->with($package);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$library->install($this->repository, $package);
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
|
|
|
|
$this->assertFileExists($this->binDir, 'Bin dir should be created');
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:43:12 +00:00
|
|
|
/**
|
|
|
|
* @depends testInstallerCreationShouldNotCreateVendorDirectory
|
|
|
|
* @depends testInstallerCreationShouldNotCreateBinDirectory
|
|
|
|
*/
|
2011-09-23 21:23:16 +00:00
|
|
|
public function testUpdate()
|
|
|
|
{
|
2013-09-22 17:42:05 +00:00
|
|
|
$filesystem = $this->getMockBuilder('Composer\Util\Filesystem')
|
|
|
|
->getMock();
|
|
|
|
$filesystem
|
|
|
|
->expects($this->once())
|
2013-09-25 19:07:55 +00:00
|
|
|
->method('rename')
|
2013-11-04 12:36:30 +00:00
|
|
|
->with($this->vendorDir.'/package1/oldtarget', $this->vendorDir.'/package1/newtarget');
|
2013-09-22 17:42:05 +00:00
|
|
|
|
2011-09-23 21:23:16 +00:00
|
|
|
$initial = $this->createPackageMock();
|
|
|
|
$target = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$initial
|
2013-09-20 04:04:15 +00:00
|
|
|
->expects($this->once())
|
2011-12-15 14:14:33 +00:00
|
|
|
->method('getPrettyName')
|
2011-09-23 22:30:17 +00:00
|
|
|
->will($this->returnValue('package1'));
|
|
|
|
|
2013-11-04 12:36:30 +00:00
|
|
|
$initial
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue('oldtarget'));
|
|
|
|
|
2013-09-20 04:02:36 +00:00
|
|
|
$target
|
|
|
|
->expects($this->once())
|
2011-12-15 14:14:33 +00:00
|
|
|
->method('getPrettyName')
|
2011-09-23 22:30:17 +00:00
|
|
|
->will($this->returnValue('package1'));
|
|
|
|
|
2013-09-22 17:42:05 +00:00
|
|
|
$target
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue('newtarget'));
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2012-02-18 22:21:45 +00:00
|
|
|
->expects($this->exactly(3))
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('hasPackage')
|
2012-02-18 22:21:45 +00:00
|
|
|
->will($this->onConsecutiveCalls(true, false, false));
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
$this->dm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('update')
|
2013-09-22 17:42:05 +00:00
|
|
|
->with($initial, $target, $this->vendorDir.'/package1/newtarget');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->once())
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('removePackage')
|
2011-09-23 21:23:16 +00:00
|
|
|
->with($initial);
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->once())
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('addPackage')
|
|
|
|
->with($target);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2013-09-22 17:42:05 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer, 'library', $filesystem);
|
2012-04-14 13:45:25 +00:00
|
|
|
$library->update($this->repository, $initial, $target);
|
2012-02-16 20:43:12 +00:00
|
|
|
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
|
|
|
|
$this->assertFileExists($this->binDir, 'Bin dir should be created');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$library->update($this->repository, $initial, $target);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUninstall()
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer);
|
2011-09-23 21:23:16 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$package
|
2012-06-27 05:27:01 +00:00
|
|
|
->expects($this->any())
|
2011-12-15 14:14:33 +00:00
|
|
|
->method('getPrettyName')
|
2011-09-23 22:30:17 +00:00
|
|
|
->will($this->returnValue('pkg'));
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->exactly(2))
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('hasPackage')
|
2011-09-23 21:23:16 +00:00
|
|
|
->with($package)
|
|
|
|
->will($this->onConsecutiveCalls(true, false));
|
|
|
|
|
|
|
|
$this->dm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('remove')
|
2011-12-03 14:39:06 +00:00
|
|
|
->with($package, $this->vendorDir.'/pkg');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository
|
2011-09-23 21:23:16 +00:00
|
|
|
->expects($this->once())
|
2011-09-25 12:44:41 +00:00
|
|
|
->method('removePackage')
|
2011-09-23 21:23:16 +00:00
|
|
|
->with($package);
|
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$library->uninstall($this->repository, $package);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2013-08-07 08:50:12 +00:00
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
2012-04-14 13:45:25 +00:00
|
|
|
$library->uninstall($this->repository, $package);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
2011-10-30 18:10:37 +00:00
|
|
|
public function testGetInstallPath()
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer);
|
2011-10-30 18:10:37 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
2011-12-03 14:39:06 +00:00
|
|
|
$this->assertEquals($this->vendorDir.'/'.$package->getName(), $library->getInstallPath($package));
|
2011-10-30 18:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInstallPathWithTargetDir()
|
|
|
|
{
|
2012-06-24 18:11:06 +00:00
|
|
|
$library = new LibraryInstaller($this->io, $this->composer);
|
2011-10-30 18:10:37 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue('Some/Namespace'));
|
2011-12-03 14:39:06 +00:00
|
|
|
$package
|
|
|
|
->expects($this->any())
|
2011-12-15 14:14:33 +00:00
|
|
|
->method('getPrettyName')
|
2011-12-03 14:39:06 +00:00
|
|
|
->will($this->returnValue('foo/bar'));
|
2011-10-30 18:10:37 +00:00
|
|
|
|
2011-12-15 14:14:33 +00:00
|
|
|
$this->assertEquals($this->vendorDir.'/'.$package->getPrettyName().'/Some/Namespace', $library->getInstallPath($package));
|
2011-10-30 18:10:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-16 09:22:30 +00:00
|
|
|
protected function createPackageMock()
|
2011-09-23 21:23:16 +00:00
|
|
|
{
|
2012-08-23 13:52:40 +00:00
|
|
|
return $this->getMockBuilder('Composer\Package\Package')
|
2013-01-30 09:44:07 +00:00
|
|
|
->setConstructorArgs(array(md5(mt_rand()), '1.0.0.0', '1.0.0'))
|
2011-09-23 21:23:16 +00:00
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
}
|