Browse Source

Make sure aliased packages are removed correctly from the repository, fixes #7167

Jordi Boggiano 7 years ago
parent
commit
036fc44c25

+ 7 - 0
src/Composer/Repository/ArrayRepository.php

@@ -167,6 +167,13 @@ class ArrayRepository extends BaseRepository
     {
         $packageId = $package->getUniqueName();
 
+        if ($package instanceof AliasPackage) {
+            $aliasedPackage = $package->getAliasOf();
+            if ($this === $aliasedPackage->getRepository()) {
+                $this->removePackage($aliasedPackage);
+            }
+        }
+
         foreach ($this->getPackages() as $key => $repoPackage) {
             if ($packageId === $repoPackage->getUniqueName()) {
                 array_splice($this->packages, $key, 1);

+ 5 - 1
tests/Composer/Test/Repository/ArrayRepositoryTest.php

@@ -68,7 +68,7 @@ class ArrayRepositoryTest extends TestCase
         $this->assertEquals('bar', $bar[0]->getName());
     }
 
-    public function testAutomaticallyAddAliasedPackage()
+    public function testAutomaticallyAddAndRemoveAliasedPackage()
     {
         $repo = new ArrayRepository();
 
@@ -80,6 +80,10 @@ class ArrayRepositoryTest extends TestCase
         $this->assertCount(2, $repo);
         $this->assertTrue($repo->hasPackage($this->getPackage('foo', '1')));
         $this->assertTrue($repo->hasPackage($this->getPackage('foo', '2')));
+
+        $repo->removePackage($alias);
+
+        $this->assertCount(0, $repo);
     }
 
     public function testSearch()