From 07f706e57de283d152bfba1af0dc25b660cffc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=BClke?= Date: Fri, 21 Jul 2023 11:28:36 +0200 Subject: [PATCH] Fix 'composer show --platform ' erroring if no composer.json is present (#11533) Sort of related to #11046 (although this is not a regression, but didn't work before, either) --- src/Composer/Command/ShowCommand.php | 4 ++-- tests/Composer/Test/Command/ShowCommandTest.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 603a26e9c..50fd058aa 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -815,7 +815,7 @@ EOT $io->write('homepage : ' . $package->getHomepage()); $io->write('source : ' . sprintf('[%s] %s %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference())); $io->write('dist : ' . sprintf('[%s] %s %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('path : ' . realpath($path)); @@ -976,7 +976,7 @@ EOT ]; } - 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); diff --git a/tests/Composer/Test/Command/ShowCommandTest.php b/tests/Composer/Test/Command/ShowCommandTest.php index 0e1bf0ada..4dbf25872 100644 --- a/tests/Composer/Test/Command/ShowCommandTest.php +++ b/tests/Composer/Test/Command/ShowCommandTest.php @@ -288,12 +288,19 @@ vendor/package 1.1.0 ! 1.2.0", trim($appTester->getDispla 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