diff --git a/src/Composer/Plugin.php b/src/Composer/Plugin.php index 66fe1d0..9ef26fd 100644 --- a/src/Composer/Plugin.php +++ b/src/Composer/Plugin.php @@ -209,18 +209,26 @@ public function postUpdate(Event $event) public function getMissingRequires(InstalledRepositoryInterface $repo, array $requires, bool $isProject): array { $allPackages = []; - $devPackages = method_exists($repo, 'getDevPackageNames') ? array_flip($repo->getDevPackageNames()) : []; + $devPackages = method_exists($repo, 'getDevPackageNames') ? array_fill_keys($repo->getDevPackageNames(), true) : []; - // One must require "php-http/discovery" or "friendsofphp/well-known-implementations" + // One must require "php-http/discovery" // to opt-in for auto-installation of virtual package implementations - if (!isset($requires[0]['php-http/discovery']) && !isset($requires[0]['friendsofphp/well-known-implementations'])) { + if (!isset($requires[0]['php-http/discovery'])) { $requires = [[], []]; } foreach ($repo->getPackages() as $package) { - $allPackages[$package->getName()] = $package; + $allPackages[$package->getName()] = true; - if (isset($package->getRequires()['php-http/discovery']) || isset($package->getRequires()['friendsofphp/well-known-implementations'])) { + if (1 < \count($names = $package->getNames(false))) { + $allPackages += array_fill_keys($names, false); + + if (isset($devPackages[$package->getName()])) { + $devPackages += $names; + } + } + + if (isset($package->getRequires()['php-http/discovery'])) { $requires[(int) isset($devPackages[$package->getName()])] += $package->getRequires(); } } diff --git a/tests/Composer/PluginTest.php b/tests/Composer/PluginTest.php index 13e9d4b..bf4fa67 100644 --- a/tests/Composer/PluginTest.php +++ b/tests/Composer/PluginTest.php @@ -79,5 +79,31 @@ public static function provideMissingRequires() ]]; yield 'move-to-require' => [$expected, $repo, $rootRequires, []]; + + $package = new Package('symfony/symfony', '1.0.0.0', '1.0'); + $package->setReplaces([new Link('symfony/symfony', 'symfony/http-client', new Constraint(Constraint::STR_OP_GE, '1'))]); + + $repo = new InstalledArrayRepository([ + 'php-http/discovery' => new Package('php-http/discovery', '1.0.0.0', '1.0'), + 'symfony/symfony' => $package, + ]); + + $rootRequires = [ + 'php-http/discovery' => $link, + 'php-http/async-client-implementation' => $link, + 'symfony/symfony' => $link, + ]; + + $expected = [[ + 'php-http/async-client-implementation' => [ + 'guzzlehttp/promises', + 'php-http/message-factory', + ], + 'psr/http-factory-implementation' => [ + 'nyholm/psr7', + ], + ], [], []]; + + yield 'replace' => [$expected, $repo, $rootRequires, []]; } }