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;
|
|
|
|
|
|
|
|
class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private $dir;
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
$this->dir = sys_get_temp_dir().'/composer';
|
|
|
|
if (is_dir($this->dir)) {
|
|
|
|
rmdir($this->dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
$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-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
$this->assertTrue(is_dir($this->dir));
|
|
|
|
|
|
|
|
$file = sys_get_temp_dir().'/file';
|
|
|
|
touch($file);
|
|
|
|
|
|
|
|
$this->setExpectedException('UnexpectedValueException');
|
2011-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($file, $this->dm, $this->repository);
|
2011-09-23 21:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsInstalled()
|
|
|
|
{
|
2011-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($this->dir, $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-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($this->dir, $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())
|
|
|
|
->method('getName')
|
|
|
|
->will($this->returnValue('some/package'));
|
|
|
|
|
2011-09-23 21:23:16 +00:00
|
|
|
$this->dm
|
|
|
|
->expects($this->once())
|
|
|
|
->method('download')
|
2011-10-22 17:49:54 +00:00
|
|
|
->with($package, $this->dir.'/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-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($this->dir, $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())
|
|
|
|
->method('getName')
|
|
|
|
->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-10-22 17:49:54 +00:00
|
|
|
->with($initial, $target, $this->dir.'/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-09-25 12:44:41 +00:00
|
|
|
$library = new LibraryInstaller($this->dir, $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())
|
|
|
|
->method('getName')
|
|
|
|
->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-10-22 17:49:54 +00:00
|
|
|
->with($package, $this->dir.'/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-09-25 12:44:41 +00:00
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
|
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
|
|
|
$this->assertEquals($this->dir.'/'.$package->getName(), $library->getInstallPath($package));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInstallPathWithTargetDir()
|
|
|
|
{
|
|
|
|
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
|
|
|
|
$package = $this->createPackageMock();
|
|
|
|
|
|
|
|
$package
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getTargetDir')
|
|
|
|
->will($this->returnValue('Some/Namespace'));
|
|
|
|
|
|
|
|
$this->assertEquals($this->dir.'/'.$package->getName().'/Some/Namespace', $library->getInstallPath($package));
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|