1
0
Fork 0

Fix handling of metapackages with null paths, and handling of paths which do not have a shortest-path and require an absolute path to be addressed

pull/9699/head
Jordi Boggiano 2021-05-21 13:54:18 +02:00
parent 518b44a810
commit 3fe4f84a76
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
4 changed files with 48 additions and 10 deletions

View File

@ -159,8 +159,13 @@ class FilesystemRepository extends WritableArrayRepository
} else {
$lines .= "array(),\n";
}
} elseif ($key === 'install_path') {
$lines .= "__DIR__ . " . var_export('/' . $value, true) . ",\n";
} elseif ($key === 'install_path' && is_string($value)) {
$fs = new Filesystem();
if ($fs->isAbsolutePath($value)) {
$lines .= var_export($value, true) . ",\n";
} else {
$lines .= "__DIR__ . " . var_export('/' . $value, true) . ",\n";
}
} else {
$lines .= var_export($value, true) . ",\n";
}

View File

@ -52,6 +52,7 @@ class InstalledVersionsTest extends TestCase
'foo/impl',
'foo/impl2',
'foo/replaced',
'meta/package',
);
$this->assertSame($names, InstalledVersions::getInstalledPackages());
}
@ -74,6 +75,7 @@ class InstalledVersionsTest extends TestCase
array(true, '__root__'),
array(true, 'b/replacer'),
array(false, 'not/there'),
array(true, 'meta/package'),
);
}
@ -246,8 +248,8 @@ class InstalledVersionsTest extends TestCase
public function testGetInstallPath()
{
$this->assertSame($this->root . '/./', \Composer\InstalledVersions::getInstallPath('__root__'));
$this->assertSame($this->root . '/foo/bar/vendor/woop/woop', \Composer\InstalledVersions::getInstallPath('c/c'));
$this->assertSame(realpath($this->root), realpath(\Composer\InstalledVersions::getInstallPath('__root__')));
$this->assertSame('/foo/bar/vendor/c/c', \Composer\InstalledVersions::getInstallPath('c/c'));
$this->assertNull(\Composer\InstalledVersions::getInstallPath('foo/impl'));
}
}

View File

@ -12,6 +12,7 @@
namespace Composer\Test\Repository;
use Composer\Package\RootPackageInterface;
use Composer\Repository\FilesystemRepository;
use Composer\Test\TestCase;
use Composer\Json\JsonFile;
@ -157,12 +158,34 @@ class FilesystemRepositoryTest extends TestCase
$pkg = $this->getPackage('c/c', '3.0');
$repository->addPackage($pkg);
$pkg = $this->getPackage('meta/package', '3.0');
$pkg->setType('metapackage');
$repository->addPackage($pkg);
$im = $this->getMockBuilder('Composer\Installer\InstallationManager')
->disableOriginalConstructor()
->getMock();
$im->expects($this->any())
->method('getInstallPath')
->will($this->returnValue('/foo/bar/vendor/woop/woop'));
->will($this->returnCallback(function ($package) use ($dir) {
// check for empty paths handling
if ($package->getType() === 'metapackage') {
return '';
}
if ($package->getName() === 'c/c') {
// check for absolute paths
return '/foo/bar/vendor/c/c';
}
// check for cwd
if ($package instanceof RootPackageInterface) {
return $dir;
}
// check for relative paths
return 'vendor/'.$package->getName();
}));
$repository->write(true, $im);
$this->assertSame(require __DIR__.'/Fixtures/installed.php', require $dir.'/installed.php');

View File

@ -42,7 +42,7 @@ return array(
'version' => '1.1.0.0',
'type' => 'library',
// @phpstan-ignore-next-line
'install_path' => $dir . '/foo/bar/vendor/woop/woop',
'install_path' => $dir . '/vendor/a/provider',
'aliases' => array(),
'reference' => 'distref-as-no-source',
'dev_requirement' => false,
@ -52,7 +52,7 @@ return array(
'version' => '1.2.0.0',
'type' => 'library',
// @phpstan-ignore-next-line
'install_path' => $dir . '/foo/bar/vendor/woop/woop',
'install_path' => $dir . '/vendor/a/provider2',
'aliases' => array(
'1.4',
),
@ -64,7 +64,7 @@ return array(
'version' => '2.2.0.0',
'type' => 'library',
// @phpstan-ignore-next-line
'install_path' => $dir . '/foo/bar/vendor/woop/woop',
'install_path' => $dir . '/vendor/b/replacer',
'aliases' => array(),
'reference' => null,
'dev_requirement' => false,
@ -73,8 +73,7 @@ return array(
'pretty_version' => '3.0',
'version' => '3.0.0.0',
'type' => 'library',
// @phpstan-ignore-next-line
'install_path' => $dir . '/foo/bar/vendor/woop/woop',
'install_path' => '/foo/bar/vendor/c/c',
'aliases' => array(),
'reference' => null,
'dev_requirement' => true,
@ -103,5 +102,14 @@ return array(
'^3.0',
),
),
'meta/package' => array(
'pretty_version' => '3.0',
'version' => '3.0.0.0',
'type' => 'metapackage',
'install_path' => null,
'aliases' => array(),
'reference' => null,
'dev_requirement' => false,
)
),
);