瀏覽代碼

Fix classmap generator warnings and tests

Jordi Boggiano 11 年之前
父節點
當前提交
0902305196

+ 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)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>'

+ 15 - 3
tests/Composer/Test/Autoload/ClassMapGeneratorTest.php

@@ -13,6 +13,7 @@ namespace Composer\Test\Autoload;
 
 
 use Composer\Autoload\ClassMapGenerator;
 use Composer\Autoload\ClassMapGenerator;
 use Symfony\Component\Finder\Finder;
 use Symfony\Component\Finder\Finder;
+use Composer\Util\Filesystem;
 
 
 class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
 class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
 {
 {
@@ -107,15 +108,23 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
     {
     {
         $this->checkIfFinderIsAvailable();
         $this->checkIfFinderIsAvailable();
 
 
+        $tempDir = sys_get_temp_dir().'/ComposerTestAmbiguousRefs';
+        if (!is_dir($tempDir.'/other')) {
+            mkdir($tempDir.'/other', 0777, true);
+        }
+
         $finder = new Finder();
         $finder = new Finder();
-        $finder->files()->in(__DIR__ . '/Fixtures/Ambiguous');
+        $finder->files()->in($tempDir);
 
 
         $io = $this->getMockBuilder('Composer\IO\ConsoleIO')
         $io = $this->getMockBuilder('Composer\IO\ConsoleIO')
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
 
 
-        $a = realpath(__DIR__.'/Fixtures/Ambiguous/A.php');
-        $b = realpath(__DIR__.'/Fixtures/Ambiguous/other/A.php');
+        file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
+        file_put_contents($tempDir.'/other/A.php', "<?php\nclass A {}");
+
+        $a = realpath($tempDir.'/A.php');
+        $b = realpath($tempDir.'/other/A.php');
         $msg = '';
         $msg = '';
 
 
         $io->expects($this->once())
         $io->expects($this->once())
@@ -132,6 +141,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
         ClassMapGenerator::createMap($finder, null, $io);
         ClassMapGenerator::createMap($finder, null, $io);
 
 
         $this->assertTrue(in_array($msg, $messages, true), $msg.' not found in expected messages ('.var_export($messages, true).')');
         $this->assertTrue(in_array($msg, $messages, true), $msg.' not found in expected messages ('.var_export($messages, true).')');
+
+        $fs = new Filesystem();
+        $fs->removeDirectory($tempDir);
     }
     }
 
 
     /**
     /**

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

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

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

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

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

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

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

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