From 64f907f93f3b2235e53b1b01ca413d253c5ba5de Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 8 Apr 2020 12:20:18 +0200 Subject: [PATCH] Fix handling of aliases to use consistent format everywhere --- src/Composer/DependencyResolver/LockTransaction.php | 6 ++++-- src/Composer/Package/Locker.php | 13 +------------ .../Test/DependencyResolver/PoolBuilderTest.php | 11 ++++------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/Composer/DependencyResolver/LockTransaction.php b/src/Composer/DependencyResolver/LockTransaction.php index dbbad01d6..e9c7fea2e 100644 --- a/src/Composer/DependencyResolver/LockTransaction.php +++ b/src/Composer/DependencyResolver/LockTransaction.php @@ -122,8 +122,10 @@ class LockTransaction extends Transaction foreach ($this->resultPackages['all'] as $package) { if ($package instanceof AliasPackage) { - if (isset($aliases[$package->getName()])) { - $usedAliases[$package->getName()] = $aliases[$package->getName()]; + foreach ($aliases as $alias) { + if ($alias['package'] === $package->getName()) { + $usedAliases[] = $alias; + } } } } diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 04210bd7f..367c5e37b 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -317,24 +317,13 @@ class Locker 'content-hash' => $this->contentHash, 'packages' => null, 'packages-dev' => null, - 'aliases' => array(), + 'aliases' => $aliases, 'minimum-stability' => $minimumStability, 'stability-flags' => $stabilityFlags, 'prefer-stable' => $preferStable, 'prefer-lowest' => $preferLowest, ); - foreach ($aliases as $package => $versions) { - foreach ($versions as $version => $alias) { - $lock['aliases'][] = array( - 'alias' => $alias['alias'], - 'alias_normalized' => $alias['alias_normalized'], - 'version' => $version, - 'package' => $package, - ); - } - } - $lock['packages'] = $this->lockPackages($packages); if (null !== $devPackages) { $lock['packages-dev'] = $this->lockPackages($devPackages); diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index 58f8fda15..647ee2c2d 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -46,12 +46,9 @@ class PoolBuilderTest extends TestCase }, $stabilityFlags); $parser = new VersionParser(); - $normalizedAliases = array(); - foreach ($rootAliases as $alias) { - $normalizedAliases[$alias['package']][$parser->normalize($alias['version'])] = array( - 'alias' => $alias['alias'], - 'alias_normalized' => $parser->normalize($alias['alias']), - ); + foreach ($rootAliases as $index => $alias) { + $rootAliases[$index]['version'] = $parser->normalize($alias['version']); + $rootAliases[$index]['alias_normalized'] = $parser->normalize($alias['alias']); } $loader = new ArrayLoader(); @@ -74,7 +71,7 @@ class PoolBuilderTest extends TestCase return $pkg; }; - $repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $normalizedAliases); + $repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $rootAliases); $repositorySet->addRepository($repo = new ArrayRepository()); foreach ($packages as $package) { $repo->addPackage($loadPackage($package));