1
0
Fork 0

Add error when composer show --direct <transient-dependency> is used to show a dependency which is not direct, fixes #11728

pull/11794/head
Jordi Boggiano 2024-01-11 09:52:36 +01:00
parent 3427bee1f2
commit 55db88f51b
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 24 additions and 0 deletions

View File

@ -299,6 +299,12 @@ EOT
} elseif (null !== $packageFilter && !str_contains($packageFilter, '*')) {
[$package, $versions] = $this->getPackage($installedRepo, $repos, $packageFilter, $input->getArgument('version'));
if (isset($package) && $input->getOption('direct')) {
if (!in_array($package->getName(), $this->getRootRequires(), true)) {
throw new \InvalidArgumentException('Package "' . $package->getName() . '" is installed but not a direct dependent of the root package.');
}
}
if (!isset($package)) {
$options = $input->getOptions();
$hint = '';

View File

@ -18,6 +18,7 @@ use Composer\Pcre\Regex;
use Composer\Repository\PlatformRepository;
use Composer\Test\TestCase;
use DateTimeImmutable;
use InvalidArgumentException;
class ShowCommandTest extends TestCase
{
@ -298,6 +299,23 @@ Transitive dependencies not required in composer.json:
vendor/package 1.1.0 <highlight>! 1.2.0</highlight>", trim($appTester->getDisplay(true)));
}
public function testShowDirectWithNameOnlyShowsDirectDependents(): void
{
self::expectException(InvalidArgumentException::class);
self::expectExceptionMessage('Package "vendor/package" is installed but not a direct dependent of the root package.');
$this->initTempComposer([
'repositories' => [],
]);
$this->createInstalledJson([
self::getPackage('vendor/package', '1.0.0'),
]);
$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'show', '--direct' => true, 'package' => 'vendor/package']);
}
public function testShowPlatformOnlyShowsPlatformPackages(): void
{
$this->initTempComposer([