diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 2bb0c98b1..ca1fc10d4 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -939,16 +939,23 @@ INITIALIZER; { $packages = array(); $include = array(); + $replacedBy = array(); foreach ($packageMap as $item) { $package = $item[0]; $name = $package->getName(); $packages[$name] = $package; + foreach ($package->getReplaces() as $replace) { + $replacedBy[$replace->getTarget()] = $name; + } } - $add = function (PackageInterface $package) use (&$add, $packages, &$include) { + $add = function (PackageInterface $package) use (&$add, $packages, &$include, $replacedBy) { foreach ($package->getRequires() as $link) { $target = $link->getTarget(); + if (isset($replacedBy[$target])) { + $target = $replacedBy[$target]; + } if (!isset($include[$target])) { $include[$target] = true; if (isset($packages[$target])) { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 055b03e1c..3cd8f7ff2 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -486,6 +486,58 @@ class AutoloadGeneratorTest extends TestCase $this->assertFileExists($this->vendorDir.'/composer/autoload_classmap.php', "ClassMap file needs to be generated, even if empty."); } + public function testNonDevAutoloadReplacesNestedRequirements() + { + $package = new Package('a', '1.0', '1.0'); + $package->setRequires(array( + new Link('a', 'a/a') + )); + + $packages = array(); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); + $packages[] = $c = new Package('c/c', '1.0', '1.0'); + $packages[] = $d = new Package('d/d', '1.0', '1.0'); + $packages[] = $e = new Package('e/e', '1.0', '1.0'); + $a->setAutoload(array('classmap' => array('src/A.php'))); + $a->setRequires(array( + new Link('a/a', 'b/b') + )); + $b->setAutoload(array('classmap' => array('src/B.php'))); + $b->setRequires(array( + new Link('b/b', 'e/e') + )); + $c->setAutoload(array('classmap' => array('src/C.php'))); + $c->setReplaces(array( + new Link('c/c', 'b/b') + )); + $c->setRequires(array( + new Link('c/c', 'd/d') + )); + $d->setAutoload(array('classmap' => array('src/D.php'))); + $e->setAutoload(array('classmap' => array('src/E.php'))); + + $this->repository->expects($this->once()) + ->method('getCanonicalPackages') + ->will($this->returnValue($packages)); + + $this->fs->ensureDirectoryExists($this->vendorDir.'/a/a/src'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/b/b/src'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/c/c/src'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/d/d/src'); + $this->fs->ensureDirectoryExists($this->vendorDir.'/e/e/src'); + + file_put_contents($this->vendorDir.'/a/a/src/A.php', 'vendorDir.'/b/b/src/B.php', 'vendorDir.'/c/c/src/C.php', 'vendorDir.'/d/d/src/D.php', 'vendorDir.'/e/e/src/E.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_5'); + + $this->assertAutoloadFiles('classmap9', $this->vendorDir.'/composer', 'classmap'); + } + public function testPharAutoload() { $package = new Package('a', '1.0', '1.0'); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap9.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap9.php new file mode 100644 index 000000000..f9ad3ca30 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap9.php @@ -0,0 +1,12 @@ + $vendorDir . '/a/a/src/A.php', + 'C' => $vendorDir . '/c/c/src/C.php', + 'D' => $vendorDir . '/d/d/src/D.php', +);