[ClassMapGenerator] Refine the findClasses method
The code could not throwpull/1315/head
parent
1726fd4d8b
commit
ff5c428d60
|
@ -96,6 +96,10 @@ class ClassMapGenerator
|
|||
|
||||
try {
|
||||
$contents = php_strip_whitespace($path);
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
if (!preg_match('{\b(?:class|interface'.$traits.')\b}i', $contents)) {
|
||||
return array();
|
||||
}
|
||||
|
@ -116,8 +120,6 @@ class ClassMapGenerator
|
|||
$namespace = '';
|
||||
|
||||
for ($i = 0, $len = count($matches['type']); $i < $len; $i++) {
|
||||
$name = $matches['name'][$i];
|
||||
|
||||
if (!empty($matches['ns'][$i])) {
|
||||
$namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\';
|
||||
} else {
|
||||
|
@ -126,8 +128,6 @@ class ClassMapGenerator
|
|||
}
|
||||
|
||||
return $classes;
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,19 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
|
|||
), ClassMapGenerator::createMap($finder));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Could not scan for classes inside
|
||||
*/
|
||||
public function testThrowsWhenFileDoesNotExist()
|
||||
{
|
||||
$r = new \ReflectionClass('Composer\\Autoload\\ClassMapGenerator');
|
||||
$find = $r->getMethod('findClasses');
|
||||
$find->setAccessible(true);
|
||||
|
||||
$find->invoke(null, __DIR__.'/no-file');
|
||||
}
|
||||
|
||||
protected function assertEqualsNormalized($expected, $actual, $message = null)
|
||||
{
|
||||
foreach ($expected as $ns => $path) {
|
||||
|
|
Loading…
Reference in New Issue