From 4904e7618512583ff46cc675a75f620f2713b247 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 30 Oct 2011 19:10:37 +0100 Subject: [PATCH] Install every package in its own directory, fixes #73 --- src/Composer/Installer/LibraryInstaller.php | 7 ++--- .../Test/Installer/LibraryInstallerTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 332e8e8b6..f7525777a 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -123,10 +123,7 @@ class LibraryInstaller implements InstallerInterface */ public function getInstallPath(PackageInterface $package) { - if (null === $package->getTargetDir()) { - return ($this->directory ? $this->directory.'/' : '').$package->getName(); - } - - return ($this->directory ? $this->directory.'/' : '').$package->getTargetDir(); + $targetDir = $package->getTargetDir(); + return ($this->directory ? $this->directory.'/' : '') . $package->getName() . ($targetDir ? '/'.$targetDir : ''); } } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index c5be9cbb6..700e7afbd 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -160,6 +160,32 @@ class LibraryInstallerTest extends \PHPUnit_Framework_TestCase $library->uninstall($package); } + 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)); + } + private function createPackageMock() { return $this->getMockBuilder('Composer\Package\MemoryPackage')