1
0
Fork 0

getCanonicalPackages returns packages with same name in different versions

pull/4324/head
Malte Wunsch 2015-08-03 18:28:04 +02:00
parent 06feb19b2c
commit 767279b41a
3 changed files with 34 additions and 3 deletions

View File

@ -26,6 +26,7 @@ use Composer\Package\LinkConstraint\VersionConstraint;
*/ */
class ArrayRepository implements RepositoryInterface class ArrayRepository implements RepositoryInterface
{ {
/** @var PackageInterface[] */
protected $packages; protected $packages;
public function __construct(array $packages = array()) public function __construct(array $packages = array())

View File

@ -42,11 +42,12 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit
{ {
$packages = $this->getPackages(); $packages = $this->getPackages();
// get at most one package of each name, prefering non-aliased ones // get at most one package of each (name, version) combination, prefering non-aliased ones
$packagesByName = array(); $packagesByName = array();
foreach ($packages as $package) { foreach ($packages as $package) {
if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) { $index = $package->getName() . $package->getVersion();
$packagesByName[$package->getName()] = $package; if (!isset($packagesByName[$index]) || $packagesByName[$index] instanceof AliasPackage) {
$packagesByName[$index] = $package;
} }
} }

View File

@ -0,0 +1,29 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Repository;
use Composer\Repository\WritableArrayRepository;
use Composer\TestCase;
final class WritableArrayRepositoryTest extends TestCase
{
public function testGetCanonicalPackagesReturnsDifferentVersionsOfSameNamedPackage()
{
$repository = new WritableArrayRepository();
$repository->addPackage($this->getPackage('foo', 1));
$repository->addPackage($this->getPackage('foo', 2));
$this->assertCount(2, $repository->getCanonicalPackages());
}
}