Skip to content

Commit 239729e

Browse files
author
Steve Buzonas
committed
return absolute paths in installer, fixes composer#307
1 parent a3595c5 commit 239729e

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

src/Composer/Installers/Installer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ public function getInstallPath(PackageInterface $package)
9797
$class = 'Composer\\Installers\\' . $this->supportedTypes[$frameworkType];
9898
$installer = new $class($package, $this->composer, $this->getIO());
9999

100-
return $installer->getInstallPath($package, $frameworkType);
100+
$basePath = realpath(getcwd());
101+
102+
$installPath = $installer->getInstallPath($package, $frameworkType);
103+
104+
return $basePath.'/'.$installPath;
101105
}
102106

103107
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)

tests/Composer/Installers/Test/InstallerTest.php

+46-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function setUp()
3232
$this->config = new Config();
3333
$this->composer->setConfig($this->config);
3434

35+
$this->rootDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-root-package';
36+
$this->ensureDirectoryExistsAndClear($this->rootDir);
37+
3538
$this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'baton-test-vendor';
3639
$this->ensureDirectoryExistsAndClear($this->vendorDir);
3740

@@ -61,6 +64,7 @@ public function setUp()
6164
*/
6265
public function tearDown()
6366
{
67+
$this->fs->removeDirectory($this->rootDir);
6468
$this->fs->removeDirectory($this->vendorDir);
6569
$this->fs->removeDirectory($this->binDir);
6670
}
@@ -198,12 +202,17 @@ public function dataForTestSupport()
198202
*/
199203
public function testInstallPath($type, $path, $name, $version = '1.0.0')
200204
{
205+
$currentWorkDir = getcwd();
206+
chdir($this->rootDir);
207+
201208
$installer = new Installer($this->io, $this->composer);
202209
$package = new Package($name, $version, $version);
203210

204211
$package->setType($type);
205212
$result = $installer->getInstallPath($package);
206-
$this->assertEquals($path, $result);
213+
$this->assertEquals($this->rootDir.'/'.$path, $result);
214+
215+
chdir($currentWorkDir);
207216
}
208217

209218
/**
@@ -354,6 +363,9 @@ public function testGetCakePHPInstallPathException()
354363
*/
355364
public function testCustomInstallPath()
356365
{
366+
$currentWorkDir = getcwd();
367+
chdir($this->rootDir);
368+
357369
$installer = new Installer($this->io, $this->composer);
358370
$package = new Package('shama/ftp', '1.0.0', '1.0.0');
359371
$package->setType('cakephp-plugin');
@@ -368,29 +380,39 @@ public function testCustomInstallPath()
368380
),
369381
));
370382
$result = $installer->getInstallPath($package);
371-
$this->assertEquals('my/custom/path/Ftp/', $result);
383+
$this->assertEquals($this->rootDir.'/my/custom/path/Ftp/', $result);
384+
385+
chdir($currentWorkDir);
372386
}
373387

374388
/**
375389
* testCustomInstallerName
376390
*/
377391
public function testCustomInstallerName()
378392
{
393+
$currentWorkDir = getcwd();
394+
chdir($this->rootDir);
395+
379396
$installer = new Installer($this->io, $this->composer);
380397
$package = new Package('shama/cakephp-ftp-plugin', '1.0.0', '1.0.0');
381398
$package->setType('cakephp-plugin');
382399
$package->setExtra(array(
383400
'installer-name' => 'FTP',
384401
));
385402
$result = $installer->getInstallPath($package);
386-
$this->assertEquals('Plugin/FTP/', $result);
403+
$this->assertEquals($this->rootDir.'/Plugin/FTP/', $result);
404+
405+
chdir($currentWorkDir);
387406
}
388407

389408
/**
390409
* testCustomTypePath
391410
*/
392411
public function testCustomTypePath()
393412
{
413+
$currentWorkDir = getcwd();
414+
chdir($this->rootDir);
415+
394416
$installer = new Installer($this->io, $this->composer);
395417
$package = new Package('slbmeh/my_plugin', '1.0.0', '1.0.0');
396418
$package->setType('wordpress-plugin');
@@ -404,14 +426,19 @@ public function testCustomTypePath()
404426
),
405427
));
406428
$result = $installer->getInstallPath($package);
407-
$this->assertEquals('my/custom/path/my_plugin/', $result);
429+
$this->assertEquals($this->rootDir.'/my/custom/path/my_plugin/', $result);
430+
431+
chdir($currentWorkDir);
408432
}
409433

410434
/**
411435
* testVendorPath
412436
*/
413437
public function testVendorPath()
414438
{
439+
$currentWorkDir = getcwd();
440+
chdir($this->rootDir);
441+
415442
$installer = new Installer($this->io, $this->composer);
416443
$package = new Package('penyaskito/my_module', '1.0.0', '1.0.0');
417444
$package->setType('drupal-module');
@@ -425,27 +452,37 @@ public function testVendorPath()
425452
),
426453
));
427454
$result = $installer->getInstallPath($package);
428-
$this->assertEquals('modules/custom/my_module/', $result);
455+
$this->assertEquals($this->rootDir.'/modules/custom/my_module/', $result);
456+
457+
chdir($currentWorkDir);
429458
}
430459

431460
/**
432461
* testNoVendorName
433462
*/
434463
public function testNoVendorName()
435464
{
465+
$currentWorkDir = getcwd();
466+
chdir($this->rootDir);
467+
436468
$installer = new Installer($this->io, $this->composer);
437469
$package = new Package('sfPhpunitPlugin', '1.0.0', '1.0.0');
438470

439471
$package->setType('symfony1-plugin');
440472
$result = $installer->getInstallPath($package);
441-
$this->assertEquals('plugins/sfPhpunitPlugin/', $result);
473+
$this->assertEquals($this->rootDir.'/plugins/sfPhpunitPlugin/', $result);
474+
475+
chdir($currentWorkDir);
442476
}
443477

444478
/**
445479
* testTypo3Inflection
446480
*/
447481
public function testTypo3Inflection()
448482
{
483+
$currentWorkDir = getcwd();
484+
chdir($this->rootDir);
485+
449486
$installer = new Installer($this->io, $this->composer);
450487
$package = new Package('typo3/fluid', '1.0.0', '1.0.0');
451488

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

458495
$package->setType('typo3-flow-package');
459496
$result = $installer->getInstallPath($package);
460-
$this->assertEquals('Packages/Application/TYPO3.Fluid/', $result);
497+
$this->assertEquals($this->rootDir.'/Packages/Application/TYPO3.Fluid/', $result);
498+
499+
chdir($currentWorkDir);
461500
}
462501

463502
public function testUninstallAndDeletePackageFromLocalRepo()

0 commit comments

Comments
 (0)