diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 4d1517f74..8f8aa87d8 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -459,6 +459,11 @@ FOOTER; $packageKey = $names[$item[0]->getName()]; $target = $link->getTarget(); $targetKey = is_int($names[$target]) ? $names[$target] : $names[$names[$target]]; + + if ($targetKey <= $packageKey) { + continue; + } + $groups[$targetKey] = array_merge($groups[$targetKey], $groups[$packageKey]); foreach ($groups[$packageKey] as $originalItem) { diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index af318f4c7..51c360dae 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -328,6 +328,8 @@ class AutoloadGeneratorTest extends TestCase $packages[] = $z = new Package('z/foo', '1.0', '1.0'); $packages[] = $b = new Package('b/bar', '1.0', '1.0'); $packages[] = $c = new Package('c/lorem', '1.0', '1.0'); + $packages[] = $d = new Package('d/d', '1.0', '1.0'); + $packages[] = $e = new Package('e/e', '1.0', '1.0'); $z->setAutoload(array('files' => array('testA.php'))); $z->setRequires(array(new Link('z/foo', 'c/lorem'))); @@ -337,6 +339,11 @@ class AutoloadGeneratorTest extends TestCase $c->setAutoload(array('files' => array('testC.php'))); + $d->setAutoload(array('files' => array('testD.php'))); + + $e->setAutoload(array('files' => array('testE.php'))); + $e->setRequires(array(new Link('e/e', 'c/lorem'))); + $this->repository->expects($this->once()) ->method('getPackages') ->will($this->returnValue($packages)); @@ -344,9 +351,13 @@ class AutoloadGeneratorTest extends TestCase $this->fs->ensureDirectoryExists($this->vendorDir . '/z/foo'); $this->fs->ensureDirectoryExists($this->vendorDir . '/b/bar'); $this->fs->ensureDirectoryExists($this->vendorDir . '/c/lorem'); + $this->fs->ensureDirectoryExists($this->vendorDir . '/d/d'); + $this->fs->ensureDirectoryExists($this->vendorDir . '/e/e'); file_put_contents($this->vendorDir . '/z/foo/testA.php', 'vendorDir . '/b/bar/testB.php', 'vendorDir . '/c/lorem/testC.php', 'vendorDir . '/d/d/testD.php', 'vendorDir . '/e/e/testE.php', 'workingDir . '/root.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, 'FilesAutoloadOrder'); @@ -361,6 +372,8 @@ class AutoloadGeneratorTest extends TestCase $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency1')); $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency2')); $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency3')); + $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency4')); + $this->assertTrue(function_exists('testFilesAutoloadOrderByDependency5')); $this->assertTrue(function_exists('testFilesAutoloadOrderByDependencyRoot')); } diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php index b09592404..ac610bade 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_files_by_dependency.php @@ -34,6 +34,8 @@ class ComposerAutoloaderInitFilesAutoloadOrder require $vendorDir . '/z/foo/testA.php'; require $baseDir . '/root.php'; require $vendorDir . '/b/bar/testB.php'; + require $vendorDir . '/d/d/testD.php'; + require $vendorDir . '/e/e/testE.php'; return $loader; }