diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 73c036a37..d470ca2da 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -79,6 +79,10 @@ class ClassMapGenerator $classes = self::findClasses($filePath); foreach ($classes as $class) { + if (array_key_exists($class, $map)) { + throw new \RuntimeException('Ambiguous reference to class "'.$class.'" was found.'); + } + $map[$class] = $filePath; } } diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index ddadc89c5..fe33b1f36 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -104,6 +104,22 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase $find->invoke(null, __DIR__.'/no-file'); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Ambiguous reference to class "A" was found. + */ + public function testAmbiguousReference() + { + if (!class_exists('Symfony\\Component\\Finder\\Finder')) { + $this->markTestSkipped('Finder component is not available'); + } + + $finder = new \Symfony\Component\Finder\Finder(); + $finder->files()->in(__DIR__ . '/Fixtures/Ambiguous'); + + ClassMapGenerator::createMap($finder); + } + /** * @expectedException \RuntimeException * @expectedExceptionMessage Could not scan for classes inside diff --git a/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php b/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php new file mode 100644 index 000000000..ee9325efa --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php @@ -0,0 +1,6 @@ +