1
0
Fork 0
composer/tests/Composer/Test/Installer/LibraryInstallerTest.php

170 lines
4.8 KiB
PHP
Raw Normal View History

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;
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();
$this->repository = $this->getMockBuilder('Composer\Repository\WritableRepositoryInterface')
2011-09-23 21:23:16 +00:00
->disableOriginalConstructor()
->getMock();
}
public function testInstallerCreation()
{
$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');
$library = new LibraryInstaller($file, $this->dm, $this->repository);
2011-09-23 21:23:16 +00:00
}
public function testIsInstalled()
{
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
2011-09-23 21:23:16 +00:00
$package = $this->createPackageMock();
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->exactly(2))
->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()
{
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
2011-09-23 21:23:16 +00:00
$package = $this->createPackageMock();
$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-09-25 21:14:12 +00:00
->with($package, $this->dir.DIRECTORY_SEPARATOR.'some/package');
2011-09-23 21:23:16 +00:00
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->once())
->method('addPackage')
->with($package);
2011-09-23 21:23:16 +00:00
$library->install($package);
}
public function testUpdate()
{
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
2011-09-23 21:23:16 +00:00
$initial = $this->createPackageMock();
$target = $this->createPackageMock();
$initial
->expects($this->once())
->method('getName')
->will($this->returnValue('package1'));
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->exactly(2))
->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-09-25 21:14:12 +00:00
->with($initial, $target, $this->dir.DIRECTORY_SEPARATOR.'package1');
2011-09-23 21:23:16 +00:00
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->once())
->method('removePackage')
2011-09-23 21:23:16 +00:00
->with($initial);
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->once())
->method('addPackage')
->with($target);
2011-09-23 21:23:16 +00:00
$library->update($initial, $target);
$this->setExpectedException('InvalidArgumentException');
2011-09-23 21:23:16 +00:00
$library->update($initial, $target);
}
public function testUninstall()
{
$library = new LibraryInstaller($this->dir, $this->dm, $this->repository);
2011-09-23 21:23:16 +00:00
$package = $this->createPackageMock();
$package
->expects($this->once())
->method('getName')
->will($this->returnValue('pkg'));
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->exactly(2))
->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-09-25 21:14:12 +00:00
->with($package, $this->dir.DIRECTORY_SEPARATOR.'pkg');
2011-09-23 21:23:16 +00:00
$this->repository
2011-09-23 21:23:16 +00:00
->expects($this->once())
->method('removePackage')
2011-09-23 21:23:16 +00:00
->with($package);
$library->uninstall($package);
$this->setExpectedException('InvalidArgumentException');
2011-09-23 21:23:16 +00:00
$library->uninstall($package);
}
private function createPackageMock()
{
return $this->getMockBuilder('Composer\Package\MemoryPackage')
->setConstructorArgs(array(md5(rand()), '1.0.0'))
->getMock();
}
}