1
0
Fork 0

Merge pull request #9285 from naderman/transaction-define-total-order-package-sort

Transaction: Define a total order on packages to keep behavior on PHP8
pull/9223/head
Jordi Boggiano 2020-10-14 11:24:21 +02:00 committed by GitHub
commit d8490ee38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -61,8 +61,12 @@ class Transaction
{
$packageSort = function (PackageInterface $a, PackageInterface $b) {
// sort alias packages by the same name behind their non alias version
if ($a->getName() == $b->getName() && $a instanceof AliasPackage != $b instanceof AliasPackage) {
return $a instanceof AliasPackage ? -1 : 1;
if ($a->getName() == $b->getName()) {
if ($a instanceof AliasPackage != $b instanceof AliasPackage) {
return $a instanceof AliasPackage ? -1 : 1;
}
// if names are the same, compare version, e.g. to sort aliases reliably, actual order does not matter
return strcmp($b->getVersion(), $a->getVersion());
}
return strcmp($b->getName(), $a->getName());
};

View File

@ -58,8 +58,8 @@ class TransactionTest extends TestCase
array('job' => 'update', 'from' => $packageB, 'to' => $packageBnew),
array('job' => 'install', 'package' => $packageG),
array('job' => 'install', 'package' => $packageF),
array('job' => 'markAliasInstalled', 'package' => $packageFalias1),
array('job' => 'markAliasInstalled', 'package' => $packageFalias2),
array('job' => 'markAliasInstalled', 'package' => $packageFalias1),
array('job' => 'install', 'package' => $packageD),
);

View File

@ -32,7 +32,7 @@ Installing double aliased package
install
--EXPECT--
Installing b/b (dev-foo)
Marking b/b (dev-master) as installed, alias of b/b (dev-foo)
Marking b/b (1.0.x-dev) as installed, alias of b/b (dev-foo)
Marking b/b (dev-master) as installed, alias of b/b (dev-foo)
Installing a/a (dev-master)
Marking a/a (9999999-dev) as installed, alias of a/a (dev-master)