Browse Source

Throw RuntimeException when ambiguous reference was found.

Jan Brecka 11 năm trước cách đây
mục cha
commit
13b57112a9

+ 4 - 0
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;
             }
         }

+ 16 - 0
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

+ 6 - 0
tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php

@@ -0,0 +1,6 @@
+<?php
+
+class A
+{
+	
+}

+ 6 - 0
tests/Composer/Test/Autoload/Fixtures/Ambiguous/other/A.php

@@ -0,0 +1,6 @@
+<?php
+
+class A
+{
+	
+}