Skip to content

Commit

Permalink
Fix show --platform regression failing if no composer.json exists, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Sep 13, 2022
1 parent 9bb436e commit 4164b30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Composer/Command/ShowCommand.php
Expand Up @@ -677,7 +677,12 @@ private function printPackages(IOInterface $io, array $packages, string $indent,
*/
protected function getRootRequires(): array
{
$rootPackage = $this->requireComposer()->getPackage();
$composer = $this->tryComposer();
if ($composer === null) {
return [];
}

$rootPackage = $composer->getPackage();

return array_map(
'strtolower',
Expand Down
14 changes: 14 additions & 0 deletions tests/Composer/Test/Command/ShowCommandTest.php
Expand Up @@ -192,6 +192,20 @@ public function testShowPlatformOnlyShowsPlatformPackages(): void
}
}

public function testShowPlatformWorksWithoutComposerJson(): void
{
$this->initTempComposer([]);
unlink('./composer.json');
unlink('./auth.json');

$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]));
}
}

public function testOutdatedWithZeroMajor(): void
{
$this->initTempComposer([
Expand Down

0 comments on commit 4164b30

Please sign in to comment.