From e949038c0ff0d5b70ddf3ead6259c4aedcaea041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 12 Sep 2013 13:28:17 +0200 Subject: [PATCH] Removed duplication of logic of an installation manager in a plugin manager --- src/Composer/Plugin/PluginManager.php | 27 +++++-------------- .../Test/Plugin/PluginInstallerTest.php | 8 ++++++ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 990096201..40376d145 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -232,28 +232,13 @@ class PluginManager */ public function getInstallPath(PackageInterface $package, $global = false) { - $targetDir = $package->getTargetDir(); + if (!$global) { + return $this->composer->getInstallationManager()->getInstallPath($package); + } - return $this->getPackageBasePath($package, $global) . ($targetDir ? '/'.$targetDir : ''); - } + $targetDir = $package->getTargetDir(); + $vendorDir = $this->composer->getConfig()->get('home').'/vendor'; - /** - * Retrieves the base path a package gets installed into. - * - * Does not take targetDir into account. - * - * @param PackageInterface $package - * @param bool $global Whether this is a global package - * - * @return string Base path - */ - protected function getPackageBasePath(PackageInterface $package, $global = false) - { - if ($global) { - $vendorDir = $this->composer->getConfig()->get('home').'/vendor'; - } else { - $vendorDir = rtrim($this->composer->getConfig()->get('vendor-dir'), '/'); - } - return ($vendorDir ? $vendorDir.'/' : '') . $package->getPrettyName(); + return ($vendorDir ? $vendorDir.'/' : '').$package->getPrettyName().($targetDir ? '/'.$targetDir : ''); } } diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index 1c2a4cf31..3b64f2699 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -52,6 +52,13 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase ->method('getLocalRepository') ->will($this->returnValue($this->repository)); + $im = $this->getMock('Composer\Installer\InstallationManager'); + $im->expects($this->any()) + ->method('getInstallPath') + ->will($this->returnCallback(function ($package) { + return __DIR__.'/Fixtures/'.$package->getPrettyName(); + })); + $this->io = $this->getMock('Composer\IO\IOInterface'); $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock(); @@ -62,6 +69,7 @@ class PluginInstallerTest extends \PHPUnit_Framework_TestCase $this->composer->setConfig($config); $this->composer->setDownloadManager($dm); $this->composer->setRepositoryManager($rm); + $this->composer->setInstallationManager($im); $this->composer->setAutoloadGenerator($this->autoloadGenerator); $this->pm = new PluginManager($this->composer, $this->io);