Add error when composer show --direct <transient-dependency> is used to show a dependency which is not direct, fixes #11728
parent
3427bee1f2
commit
55db88f51b
|
@ -299,6 +299,12 @@ EOT
|
||||||
} elseif (null !== $packageFilter && !str_contains($packageFilter, '*')) {
|
} elseif (null !== $packageFilter && !str_contains($packageFilter, '*')) {
|
||||||
[$package, $versions] = $this->getPackage($installedRepo, $repos, $packageFilter, $input->getArgument('version'));
|
[$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)) {
|
if (!isset($package)) {
|
||||||
$options = $input->getOptions();
|
$options = $input->getOptions();
|
||||||
$hint = '';
|
$hint = '';
|
||||||
|
|
|
@ -18,6 +18,7 @@ use Composer\Pcre\Regex;
|
||||||
use Composer\Repository\PlatformRepository;
|
use Composer\Repository\PlatformRepository;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class ShowCommandTest extends TestCase
|
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)));
|
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
|
public function testShowPlatformOnlyShowsPlatformPackages(): void
|
||||||
{
|
{
|
||||||
$this->initTempComposer([
|
$this->initTempComposer([
|
||||||
|
|
Loading…
Reference in New Issue