From 1ff1b8ac1f77019daa79db0f18c77bd38851f2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 17 Oct 2012 12:00:45 +0200 Subject: [PATCH] Sorted generated classmap --- src/Composer/Autoload/AutoloadGenerator.php | 9 ++++++--- tests/Composer/Test/Autoload/AutoloadGeneratorTest.php | 4 ++-- .../Test/Autoload/Fixtures/autoload_classmap3.php | 2 +- .../Test/Autoload/Fixtures/autoload_classmap4.php | 2 +- .../Test/Autoload/Fixtures/autoload_classmap5.php | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 8f8aa87d8..636f3f448 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -145,6 +145,8 @@ EOF; $classMap[$class] = '$baseDir . '.var_export($path, true).",\n"; } } + + ksort($classMap); foreach ($classMap as $class => $code) { $classmapFile .= ' '.var_export($class, true).' => '.$code; } @@ -198,13 +200,14 @@ EOF; */ public function parseAutoloads(array $packageMap) { - $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0'); - krsort($psr0); - $sortedPackageMap = $this->sortPackageMap($packageMap); + + $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0'); $classmap = $this->parseAutoloadsType($sortedPackageMap, 'classmap'); $files = $this->parseAutoloadsType($sortedPackageMap, 'files'); + krsort($psr0); + return array('psr-0' => $psr0, 'classmap' => $classmap, 'files' => $files); } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 51c360dae..626c2db07 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -238,9 +238,9 @@ class AutoloadGeneratorTest extends TestCase $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated."); $this->assertEquals( array( - 'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php', 'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/src/b.php', 'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/b/b/lib/c.php', + 'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php', ), include ($this->vendorDir.'/composer/autoload_classmap.php') ); @@ -275,9 +275,9 @@ class AutoloadGeneratorTest extends TestCase $this->assertTrue(file_exists($this->vendorDir.'/composer/autoload_classmap.php'), "ClassMap file needs to be generated."); $this->assertEquals( array( - 'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php', 'ClassMapBar' => $this->workingDir.'/composer-test-autoload/b/b/test.php', 'ClassMapBaz' => $this->workingDir.'/composer-test-autoload/c/c/foo/test.php', + 'ClassMapFoo' => $this->workingDir.'/composer-test-autoload/a/a/src/a.php', ), include ($this->vendorDir.'/composer/autoload_classmap.php') ); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php index 75c7cd741..9c5136d7f 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap3.php @@ -6,6 +6,6 @@ $vendorDir = dirname(__DIR__); $baseDir = $vendorDir; return array( - 'Main\\Foo' => $baseDir . '/src/Main/Foo.php', 'ClassMapFoo' => $baseDir . '/composersrc/foo.php', + 'Main\\Foo' => $baseDir . '/src/Main/Foo.php', ); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php index 558c5e048..7ea7c42c7 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap4.php @@ -6,7 +6,7 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php', 'ClassMapBar' => $baseDir . '/composer-test-autoload/b/b/src/b.php', 'ClassMapBaz' => $baseDir . '/composer-test-autoload/b/b/lib/c.php', + 'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php', ); diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php index e3230f953..41c1738bc 100644 --- a/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_classmap5.php @@ -6,7 +6,7 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php', 'ClassMapBar' => $baseDir . '/composer-test-autoload/b/b/test.php', 'ClassMapBaz' => $baseDir . '/composer-test-autoload/c/c/foo/test.php', + 'ClassMapFoo' => $baseDir . '/composer-test-autoload/a/a/src/a.php', );