Skip to content

Commit

Permalink
return absolute paths in installer, fixes composer#307
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Buzonas committed Jul 27, 2016
1 parent a3595c5 commit 239729e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public function getInstallPath(PackageInterface $package)
$class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
$installer = new $class($package, $this->composer, $this->getIO());

return $installer->getInstallPath($package, $frameworkType);
$basePath = realpath(getcwd());

$installPath = $installer->getInstallPath($package, $frameworkType);

return $basePath.'/'.$installPath;
}

public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
Expand Down
53 changes: 46 additions & 7 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function setUp()
$this->config = new Config();
$this->composer->setConfig($this->config);

$this->rootDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-root-package';
$this->ensureDirectoryExistsAndClear($this->rootDir);

$this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-vendor';
$this->ensureDirectoryExistsAndClear($this->vendorDir);

Expand Down Expand Up @@ -61,6 +64,7 @@ public function setUp()
*/
public function tearDown()
{
$this->fs->removeDirectory($this->rootDir);
$this->fs->removeDirectory($this->vendorDir);
$this->fs->removeDirectory($this->binDir);
}
Expand Down Expand Up @@ -198,12 +202,17 @@ public function dataForTestSupport()
*/
public function testInstallPath($type, $path, $name, $version = '1.0.0')
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package($name, $version, $version);

$package->setType($type);
$result = $installer->getInstallPath($package);
$this->assertEquals($path, $result);
$this->assertEquals($this->rootDir.'/'.$path, $result);

chdir($currentWorkDir);
}

/**
Expand Down Expand Up @@ -354,6 +363,9 @@ public function testGetCakePHPInstallPathException()
*/
public function testCustomInstallPath()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('shama/ftp', '1.0.0', '1.0.0');
$package->setType('cakephp-plugin');
Expand All @@ -368,29 +380,39 @@ public function testCustomInstallPath()
),
));
$result = $installer->getInstallPath($package);
$this->assertEquals('my/custom/path/Ftp/', $result);
$this->assertEquals($this->rootDir.'/my/custom/path/Ftp/', $result);

chdir($currentWorkDir);
}

/**
* testCustomInstallerName
*/
public function testCustomInstallerName()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('shama/cakephp-ftp-plugin', '1.0.0', '1.0.0');
$package->setType('cakephp-plugin');
$package->setExtra(array(
'installer-name' => 'FTP',
));
$result = $installer->getInstallPath($package);
$this->assertEquals('Plugin/FTP/', $result);
$this->assertEquals($this->rootDir.'/Plugin/FTP/', $result);

chdir($currentWorkDir);
}

/**
* testCustomTypePath
*/
public function testCustomTypePath()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('slbmeh/my_plugin', '1.0.0', '1.0.0');
$package->setType('wordpress-plugin');
Expand All @@ -404,14 +426,19 @@ public function testCustomTypePath()
),
));
$result = $installer->getInstallPath($package);
$this->assertEquals('my/custom/path/my_plugin/', $result);
$this->assertEquals($this->rootDir.'/my/custom/path/my_plugin/', $result);

chdir($currentWorkDir);
}

/**
* testVendorPath
*/
public function testVendorPath()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('penyaskito/my_module', '1.0.0', '1.0.0');
$package->setType('drupal-module');
Expand All @@ -425,27 +452,37 @@ public function testVendorPath()
),
));
$result = $installer->getInstallPath($package);
$this->assertEquals('modules/custom/my_module/', $result);
$this->assertEquals($this->rootDir.'/modules/custom/my_module/', $result);

chdir($currentWorkDir);
}

/**
* testNoVendorName
*/
public function testNoVendorName()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('sfPhpunitPlugin', '1.0.0', '1.0.0');

$package->setType('symfony1-plugin');
$result = $installer->getInstallPath($package);
$this->assertEquals('plugins/sfPhpunitPlugin/', $result);
$this->assertEquals($this->rootDir.'/plugins/sfPhpunitPlugin/', $result);

chdir($currentWorkDir);
}

/**
* testTypo3Inflection
*/
public function testTypo3Inflection()
{
$currentWorkDir = getcwd();
chdir($this->rootDir);

$installer = new Installer($this->io, $this->composer);
$package = new Package('typo3/fluid', '1.0.0', '1.0.0');

Expand All @@ -457,7 +494,9 @@ public function testTypo3Inflection()

$package->setType('typo3-flow-package');
$result = $installer->getInstallPath($package);
$this->assertEquals('Packages/Application/TYPO3.Fluid/', $result);
$this->assertEquals($this->rootDir.'/Packages/Application/TYPO3.Fluid/', $result);

chdir($currentWorkDir);
}

public function testUninstallAndDeletePackageFromLocalRepo()
Expand Down

0 comments on commit 239729e

Please sign in to comment.