1
0
Fork 0

Merge remote-tracking branch 'wookieb/installer_dry_run'

pull/293/merge
Jordi Boggiano 2012-02-17 10:47:40 +01:00
commit 8dcb75080e
2 changed files with 35 additions and 15 deletions

View File

@ -53,10 +53,8 @@ class LibraryInstaller implements InstallerInterface
$this->type = $type;
$this->filesystem = new Filesystem();
$this->filesystem->ensureDirectoryExists($vendorDir);
$this->filesystem->ensureDirectoryExists($binDir);
$this->vendorDir = realpath($vendorDir);
$this->binDir = realpath($binDir);
$this->vendorDir = rtrim($vendorDir, '/');
$this->binDir = rtrim($binDir, '/');
}
/**
@ -82,6 +80,9 @@ class LibraryInstaller implements InstallerInterface
{
$downloadPath = $this->getInstallPath($package);
$this->filesystem->ensureDirectoryExists($this->vendorDir);
$this->filesystem->ensureDirectoryExists($this->binDir);
// remove the binaries if it appears the package files are missing
if (!is_readable($downloadPath) && $this->repository->hasPackage($package)) {
$this->removeBinaries($package);
@ -105,6 +106,9 @@ class LibraryInstaller implements InstallerInterface
$downloadPath = $this->getInstallPath($initial);
$this->filesystem->ensureDirectoryExists($this->vendorDir);
$this->filesystem->ensureDirectoryExists($this->binDir);
$this->removeBinaries($initial);
$this->downloadManager->update($initial, $target, $downloadPath);
$this->installBinaries($target);

View File

@ -22,22 +22,22 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
private $binDir;
private $dm;
private $repository;
private $library;
private $io;
private $fs;
protected function setUp()
{
$fs = new Filesystem;
$this->fs = new Filesystem;
$this->vendorDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-vendor';
if (is_dir($this->vendorDir)) {
$fs->removeDirectory($this->vendorDir);
$this->fs->removeDirectory($this->vendorDir);
}
mkdir($this->vendorDir);
$this->binDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'composer-test-bin';
if (is_dir($this->binDir)) {
$fs->removeDirectory($this->binDir);
$this->fs->removeDirectory($this->binDir);
}
mkdir($this->binDir);
@ -52,16 +52,20 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
->getMock();
}
public function testInstallerCreation()
public function testInstallerCreationShouldNotCreateVendorDirectory()
{
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);
$this->assertTrue(is_dir($this->vendorDir));
$this->fs->removeDirectory($this->vendorDir);
$file = sys_get_temp_dir().'/file';
touch($file);
new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);
$this->assertFileNotExists($this->vendorDir);
}
$this->setExpectedException('RuntimeException');
$library = new LibraryInstaller($file, $this->binDir, $this->dm, $this->repository, $this->io);
public function testInstallerCreationShouldNotCreateBinDirectory()
{
$this->fs->removeDirectory($this->binDir);
new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);
$this->assertFileNotExists($this->binDir);
}
public function testIsInstalled()
@ -79,6 +83,10 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($library->isInstalled($package));
}
/**
* @depends testInstallerCreationShouldNotCreateVendorDirectory
* @depends testInstallerCreationShouldNotCreateBinDirectory
*/
public function testInstall()
{
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);
@ -100,8 +108,14 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
->with($package);
$library->install($package);
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
$this->assertFileExists($this->binDir, 'Bin dir should be created');
}
/**
* @depends testInstallerCreationShouldNotCreateVendorDirectory
* @depends testInstallerCreationShouldNotCreateBinDirectory
*/
public function testUpdate()
{
$library = new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io);
@ -135,6 +149,8 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase
->with($target);
$library->update($initial, $target);
$this->assertFileExists($this->vendorDir, 'Vendor dir should be created');
$this->assertFileExists($this->binDir, 'Bin dir should be created');
$this->setExpectedException('InvalidArgumentException');