diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 4e7dcf496..2cdb920a8 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -84,7 +84,7 @@ class ClassMapGenerator foreach ($classes as $class) { if (!isset($map[$class])) { $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( 'Warning: Ambiguous class resolution, "'.$class.'"'. ' was found in both "'.$map[$class].'" and "'.$filePath.'", the first will be used.' diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 07e95d525..570eeab10 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -13,6 +13,7 @@ namespace Composer\Test\Autoload; use Composer\Autoload\ClassMapGenerator; use Symfony\Component\Finder\Finder; +use Composer\Util\Filesystem; class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase { @@ -107,15 +108,23 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase { $this->checkIfFinderIsAvailable(); + $tempDir = sys_get_temp_dir().'/ComposerTestAmbiguousRefs'; + if (!is_dir($tempDir.'/other')) { + mkdir($tempDir.'/other', 0777, true); + } + $finder = new Finder(); - $finder->files()->in(__DIR__ . '/Fixtures/Ambiguous'); + $finder->files()->in($tempDir); $io = $this->getMockBuilder('Composer\IO\ConsoleIO') ->disableOriginalConstructor() ->getMock(); - $a = realpath(__DIR__.'/Fixtures/Ambiguous/A.php'); - $b = realpath(__DIR__.'/Fixtures/Ambiguous/other/A.php'); + file_put_contents($tempDir.'/A.php', "expects($this->once()) @@ -132,6 +141,9 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase ClassMapGenerator::createMap($finder, null, $io); $this->assertTrue(in_array($msg, $messages, true), $msg.' not found in expected messages ('.var_export($messages, true).')'); + + $fs = new Filesystem(); + $fs->removeDirectory($tempDir); } /** diff --git a/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php b/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php deleted file mode 100644 index ee9325efa..000000000 --- a/tests/Composer/Test/Autoload/Fixtures/Ambiguous/A.php +++ /dev/null @@ -1,6 +0,0 @@ -