Fix classmap generator warnings and tests
parent
8974a1ac92
commit
0902305196
|
@ -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>'
|
||||||
|
|
|
@ -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');
|
file_put_contents($tempDir.'/A.php', "<?php\nclass A {}");
|
||||||
$b = realpath(__DIR__.'/Fixtures/Ambiguous/other/A.php');
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class A
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
class A
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class FixtureA {}
|
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class FixtureA {}
|
Loading…
Reference in New Issue