Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of replaced packages #219

Merged
merged 1 commit into from Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Composer/Plugin.php
Expand Up @@ -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();
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Composer/PluginTest.php
Expand Up @@ -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, []];
}
}