From 2467456d3f65f91af1a8c51e3c6d28fad3a87947 Mon Sep 17 00:00:00 2001 From: Wookieb Date: Thu, 16 Feb 2012 21:43:12 +0100 Subject: [PATCH] Fix installer that create vendor and bin directory even if --dry-run parameter provided * Move directories creation from constructor to "install" and "update" method * Tests for LibraryInstaller --- src/Composer/Installer/LibraryInstaller.php | 12 ++++-- .../Test/Installer/LibraryInstallerTest.php | 38 +++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 0873ed63c..1f94f4071 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -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); diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index 561143db2..3399345f0 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -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); + + new LibraryInstaller($this->vendorDir, $this->binDir, $this->dm, $this->repository, $this->io); + $this->assertFileNotExists($this->vendorDir); + } - $file = sys_get_temp_dir().'/file'; - touch($file); + public function testInstallerCreationShouldNotCreateBinDirectory() + { + $this->fs->removeDirectory($this->binDir); - $this->setExpectedException('RuntimeException'); - $library = new LibraryInstaller($file, $this->binDir, $this->dm, $this->repository, $this->io); + 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');