Skip to content

Commit

Permalink
Fix 'composer show --platform <package>' erroring if no composer.json…
Browse files Browse the repository at this point in the history
… is present (#11533)

Sort of related to #11046 (although this is not a regression, but didn't work before, either)
  • Loading branch information
dzuelke committed Jul 21, 2023
1 parent 9eb9e0d commit 07f706e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Command/ShowCommand.php
Expand Up @@ -815,7 +815,7 @@ protected function printMeta(CompletePackageInterface $package, array $versions,
$io->write('<info>homepage</info> : ' . $package->getHomepage());
$io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
$io->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
if ($installedRepo->hasPackage($package)) {
if (!PlatformRepository::isPlatformPackage($package->getName()) && $installedRepo->hasPackage($package)) {
$path = $this->requireComposer()->getInstallationManager()->getInstallPath($package);
if (is_string($path)) {
$io->write('<info>path</info> : ' . realpath($path));
Expand Down Expand Up @@ -976,7 +976,7 @@ protected function printPackageInfoAsJson(CompletePackageInterface $package, arr
];
}

if ($installedRepo->hasPackage($package)) {
if (!PlatformRepository::isPlatformPackage($package->getName()) && $installedRepo->hasPackage($package)) {
$path = $this->requireComposer()->getInstallationManager()->getInstallPath($package);
if (is_string($path)) {
$path = realpath($path);
Expand Down
7 changes: 7 additions & 0 deletions tests/Composer/Test/Command/ShowCommandTest.php
Expand Up @@ -288,12 +288,19 @@ public function testShowPlatformWorksWithoutComposerJson(): void
unlink('./composer.json');
unlink('./auth.json');

// listing packages
$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'show', '-p' => true]);
$output = trim($appTester->getDisplay(true));
foreach (Regex::matchAll('{^(\w+)}m', $output)->matches as $m) {
self::assertTrue(PlatformRepository::isPlatformPackage((string) $m[1]));
}

// getting a single package
$appTester->run(['command' => 'show', '-p' => true, 'package' => 'php']);
$appTester->assertCommandIsSuccessful();
$appTester->run(['command' => 'show', '-p' => true, '-f' => 'json', 'package' => 'php']);
$appTester->assertCommandIsSuccessful();
}

public function testOutdatedWithZeroMajor(): void
Expand Down

0 comments on commit 07f706e

Please sign in to comment.