From 54870a78c4d4092fa509da4a5d93f3080f6fc956 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 21 Mar 2024 16:59:41 +0100 Subject: [PATCH] Add a new test to confirm that show --direct works with direct dependents/dev-dependents --- .../Composer/Test/Command/ShowCommandTest.php | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/Composer/Test/Command/ShowCommandTest.php b/tests/Composer/Test/Command/ShowCommandTest.php index 331ae0017..d726c5a92 100644 --- a/tests/Composer/Test/Command/ShowCommandTest.php +++ b/tests/Composer/Test/Command/ShowCommandTest.php @@ -299,23 +299,57 @@ Transitive dependencies not required in composer.json: vendor/package 1.1.0 ! 1.2.0", trim($appTester->getDisplay(true))); } - public function testShowDirectWithNameOnlyShowsDirectDependents(): void + public function testShowDirectWithNameDoesNotShowTransientDependencies(): void { self::expectException(InvalidArgumentException::class); self::expectExceptionMessage('Package "vendor/package" is installed but not a direct dependent of the root package.'); $this->initTempComposer([ 'repositories' => [], + 'require' => [ + 'direct/dependent' => '*', + ], ]); $this->createInstalledJson([ + $direct = self::getPackage('direct/dependent', '1.0.0'), self::getPackage('vendor/package', '1.0.0'), ]); + $this->configureLinks($direct, ['require' => ['vendor/package' => '*']]); + $appTester = $this->getApplicationTester(); $appTester->run(['command' => 'show', '--direct' => true, 'package' => 'vendor/package']); } + public function testShowDirectWithNameOnlyShowsDirectDependents(): void + { + $this->initTempComposer([ + 'repositories' => [], + 'require' => [ + 'direct/dependent' => '*', + ], + 'require-dev' => [ + 'direct/dependent2' => '*', + ], + ]); + + $this->createInstalledJson([ + self::getPackage('direct/dependent', '1.0.0'), + self::getPackage('direct/dependent2', '1.0.0'), + ]); + + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'show', '--direct' => true, 'package' => 'direct/dependent']); + $appTester->assertCommandIsSuccessful(); + self::assertStringContainsString('name : direct/dependent' . "\n", $appTester->getDisplay(true)); + + $appTester = $this->getApplicationTester(); + $appTester->run(['command' => 'show', '--direct' => true, 'package' => 'direct/dependent2']); + $appTester->assertCommandIsSuccessful(); + self::assertStringContainsString('name : direct/dependent2' . "\n", $appTester->getDisplay(true)); + } + public function testShowPlatformOnlyShowsPlatformPackages(): void { $this->initTempComposer([