Removed duplication of logic of an installation manager in a plugin manager
parent
b86b8a597e
commit
e949038c0f
|
@ -232,28 +232,13 @@ class PluginManager
|
|||
*/
|
||||
public function getInstallPath(PackageInterface $package, $global = false)
|
||||
{
|
||||
$targetDir = $package->getTargetDir();
|
||||
|
||||
return $this->getPackageBasePath($package, $global) . ($targetDir ? '/'.$targetDir : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'), '/');
|
||||
if (!$global) {
|
||||
return $this->composer->getInstallationManager()->getInstallPath($package);
|
||||
}
|
||||
return ($vendorDir ? $vendorDir.'/' : '') . $package->getPrettyName();
|
||||
|
||||
$targetDir = $package->getTargetDir();
|
||||
$vendorDir = $this->composer->getConfig()->get('home').'/vendor';
|
||||
|
||||
return ($vendorDir ? $vendorDir.'/' : '').$package->getPrettyName().($targetDir ? '/'.$targetDir : '');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue