From e3be04c4430b996cec6a8e4d16e4ad481306fbac Mon Sep 17 00:00:00 2001 From: Daniel Karp Date: Sun, 30 Mar 2014 12:53:15 -0400 Subject: [PATCH] Don't show Ambiguous class resolution warning if class when not ambiguous if a class or interface is defined twice in the same class, this should not produce a warning --- src/Composer/Autoload/ClassMapGenerator.php | 2 +- .../Test/Autoload/ClassMapGeneratorTest.php | 21 +++++++++++++++++++ .../Test/Autoload/Fixtures/Unambiguous/A.php | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/Unambiguous/A.php diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 719a16102..257930f59 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) { + } elseif ($io && $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 c191c7f1d..fa9380e5f 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -133,6 +133,27 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertTrue(in_array($msg, $messages, true), $msg.' not found in expected messages ('.var_export($messages, true).')'); } + /** + * If one file has a class or interface defined more than once, + * an ambiguous reference warning should not be produced + */ + public function testUnambiguousReference() + { + $this->checkIfFinderIsAvailable(); + + $finder = new Finder(); + $finder->files()->in(__DIR__ . '/Fixtures/Unambiguous'); + + $io = $this->getMockBuilder('Composer\IO\ConsoleIO') + ->disableOriginalConstructor() + ->getMock(); + + $io->expects($this->never()) + ->method('write'); + + ClassMapGenerator::createMap($finder, null, $io); + } + /** * @expectedException \RuntimeException * @expectedExceptionMessage Could not scan for classes inside diff --git a/tests/Composer/Test/Autoload/Fixtures/Unambiguous/A.php b/tests/Composer/Test/Autoload/Fixtures/Unambiguous/A.php new file mode 100644 index 000000000..d88eba6e8 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/Unambiguous/A.php @@ -0,0 +1,6 @@ +