Browse Source

Merge pull request #2895 from SlikNL/classmap-warning-example

Improve ambiguity warning test coverage and avoid ambiguity warning for example directories
Jordi Boggiano 11 years ago
parent
commit
a023c7929a

+ 1 - 1
src/Composer/Autoload/ClassMapGenerator.php

@@ -84,7 +84,7 @@ class ClassMapGenerator
             foreach ($classes as $class) {
             foreach ($classes as $class) {
                 if (!isset($map[$class])) {
                 if (!isset($map[$class])) {
                     $map[$class] = $filePath;
                     $map[$class] = $filePath;
-                } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) {
+                } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example)s?/}i', strtr($map[$class].' '.$filePath, '\\', '/'))) {
                     $io->write(
                     $io->write(
                         '<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
                         '<warning>Warning: Ambiguous class resolution, "'.$class.'"'.
                         ' was found in both "'.$map[$class].'" and "'.$filePath.'", the first will be used.</warning>'
                         ' was found in both "'.$map[$class].'" and "'.$filePath.'", the first will be used.</warning>'

+ 27 - 4
tests/Composer/Test/Autoload/ClassMapGeneratorTest.php

@@ -152,10 +152,30 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
      */
      */
     public function testUnambiguousReference()
     public function testUnambiguousReference()
     {
     {
-        $this->checkIfFinderIsAvailable();
+        $tempDir = sys_get_temp_dir().'/ComposerTestUnambiguousRefs';
+        if (!is_dir($tempDir)) {
+            mkdir($tempDir, 0777, true);
+        }
 
 
-        $finder = new Finder();
-        $finder->files()->in(__DIR__ . '/Fixtures/Unambiguous');
+        file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
+
+        file_put_contents(
+            $tempDir.'/B.php',
+            "<?php
+                if (true) {
+                    interface B {}
+                } else {
+                    interface B extends Iterator {}
+                }
+            "
+        );
+
+        foreach (array('test', 'fixture', 'example') as $keyword) {
+            if (!is_dir($tempDir.'/'.$keyword)) {
+                mkdir($tempDir.'/'.$keyword, 0777, true);
+            }
+            file_put_contents($tempDir.'/'.$keyword.'/A.php', "<?php\nclass A {}");
+        }
 
 
         $io = $this->getMockBuilder('Composer\IO\ConsoleIO')
         $io = $this->getMockBuilder('Composer\IO\ConsoleIO')
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
@@ -164,7 +184,10 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
         $io->expects($this->never())
         $io->expects($this->never())
             ->method('write');
             ->method('write');
 
 
-        ClassMapGenerator::createMap($finder, null, $io);
+        ClassMapGenerator::createMap($tempDir, null, $io);
+
+        $fs = new Filesystem();
+        $fs->removeDirectory($tempDir);
     }
     }
 
 
     /**
     /**

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

@@ -1,6 +0,0 @@
-<?php
-if (PHP_VERSION_ID < 50400) {
-    interface A extends Iterator, ArrayAccess { }
-} else {
-    interface A extends Iterator, ArrayAccess, JsonSerializable { }
-}

+ 0 - 3
tests/Composer/Test/Autoload/Fixtures/Unambiguous/tests/FixtureA.php

@@ -1,3 +0,0 @@
-<?php
-
-class FixtureA {}

+ 0 - 3
tests/Composer/Test/Autoload/Fixtures/Unambiguous/tests/FixtureA2.php

@@ -1,3 +0,0 @@
-<?php
-
-class FixtureA {}