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;
|
|
|
|
use Composer\DependencyResolver\Operation;
|
2011-12-03 14:39:06 +00:00
|
|
|
use Composer\Downloader\Util\Filesystem;
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
private $vendorDir;
|
|
|
|
private $binDir;
|
2011-09-23 21:23:16 +00:00
|
|
|
private $dm;
|
2011-09-25 12:44:41 +00:00
|
|
|
private $repository;
|
2011-09-23 21:23:16 +00:00
|
|
|
private $library;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$fs = new Filesystem;
|
|
|
|
|
|
|
|
$this->vendorDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'composer-test-vendor';
|
|
|
|
if (is_dir($this->vendorDir)) {
|
|
|
|
$fs->removeDirectory($this->vendorDir);
|
|
|
|
}
|
|
|
|
mkdir($this->vendorDir);
|
|
|
|
|
|
|
|
$this->binDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'composer-test-bin';
|
|
|
|
if (is_dir($this->binDir)) {
|
|
|
|
$fs->removeDirectory($this->binDir);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
2011-12-03 14:39:06 +00:00
|
|
|
mkdir($this->binDir);
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
$this->dm = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->repository = $this->getMockBuilder('Composer\Repository\WritableRepositoryInterface')
|
2011-09-23 21:23:16 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstallerCreation()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
|
|
|
$this->assertTrue(is_dir($this->vendorDir));
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
$file = sys_get_temp_dir().'/file';
|
|
|
|
touch($file);
|
|
|
|
|
2011-12-03 14:39:06 +00:00
|
|
|
$this->setExpectedException('RuntimeException');
|
|
|
|
$library = new LibraryInstaller($file, $this->binDir, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalled()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
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));
|
|
|
|
|
|
|
|
$this->assertTrue($library->isInstalled($package));
|
|
|
|
$this->assertFalse($library->isInstalled($package));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInstall()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$package
|
|
|
|
->expects($this->once())
|
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
|
|
|
|
|
|
|
$library->install($package);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
$initial = $this->createPackageMock();
|
|
|
|
$target = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$initial
|
|
|
|
->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'));
|
|
|
|
|
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($initial)
|
|
|
|
->will($this->onConsecutiveCalls(true, false));
|
|
|
|
|
|
|
|
$this->dm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('update')
|
2011-12-03 14:39:06 +00:00
|
|
|
->with($initial, $target, $this->vendorDir.'/package1');
|
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
|
|
|
|
|
|
|
$library->update($initial, $target);
|
|
|
|
|
2011-09-25 12:44:41 +00:00
|
|
|
$this->setExpectedException('InvalidArgumentException');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
$library->update($initial, $target);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUninstall()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
2011-09-23 22:30:17 +00:00
|
|
|
$package
|
|
|
|
->expects($this->once())
|
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);
|
|
|
|
|
|
|
|
$library->uninstall($package);
|
|
|
|
|
2011-11-21 17:19:32 +00:00
|
|
|
// TODO re-enable once #125 is fixed and we throw exceptions again
|
|
|
|
// $this->setExpectedException('InvalidArgumentException');
|
2011-09-23 21:23:16 +00:00
|
|
|
|
|
|
|
$library->uninstall($package);
|
|
|
|
}
|
|
|
|
|
2011-10-30 18:10:37 +00:00
|
|
|
public function testGetInstallPath()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
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()
|
|
|
|
{
|
2011-12-03 14:39:06 +00:00
|
|
|
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository);
|
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
|
|
|
}
|
|
|
|
|
2011-09-23 21:23:16 +00:00
|
|
|
private function createPackageMock()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Composer\Package\MemoryPackage')
|
2011-11-20 14:06:12 +00:00
|
|
|
->setConstructorArgs(array(md5(rand()), '1.0.0.0', '1.0.0'))
|
2011-09-23 21:23:16 +00:00
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
}
|