1
0
Fork 0

Add whitelist to the classmap generator to allow skipping of Test files

pull/811/head
Jordi Boggiano 2012-06-20 13:05:03 +02:00
parent 48c46ce3b6
commit ee14950972
2 changed files with 13 additions and 3 deletions

View File

@ -121,7 +121,12 @@ EOF;
foreach ($autoloads['psr-0'] as $namespace => $paths) { foreach ($autoloads['psr-0'] as $namespace => $paths) {
foreach ($paths as $dir) { foreach ($paths as $dir) {
$dir = $this->getPath($filesystem, $relVendorPath, $vendorPath, $dir); $dir = $this->getPath($filesystem, $relVendorPath, $vendorPath, $dir);
foreach (ClassMapGenerator::createMap($dir) as $class => $path) { $whitelist = sprintf(
'{%s/%s.+(?<!(?<!/)Test\.php)$}',
preg_quote(rtrim($dir, '/')),
strpos($namespace, '_') === false ? preg_quote(strtr($namespace, '\\', '/')) : ''
);
foreach (ClassMapGenerator::createMap($dir, $whitelist) as $class => $path) {
if (0 === strpos($class, $namespace)) { if (0 === strpos($class, $namespace)) {
$path = '/'.$filesystem->findShortestPath(getcwd(), $path, true); $path = '/'.$filesystem->findShortestPath(getcwd(), $path, true);
if (!isset($classMap[$class])) { if (!isset($classMap[$class])) {
@ -304,7 +309,7 @@ EOF;
// path starts with vendor dir // path starts with vendor dir
return $vendorPath . substr($path, strlen($relVendorPath)); return $vendorPath . substr($path, strlen($relVendorPath));
} }
return getcwd().'/'.$path; return strtr(getcwd(), '\\', '/').'/'.$path;
} }
return $path; return $path;

View File

@ -41,10 +41,11 @@ class ClassMapGenerator
* Iterate over all files in the given directory searching for classes * Iterate over all files in the given directory searching for classes
* *
* @param Iterator|string $dir The directory to search in or an iterator * @param Iterator|string $dir The directory to search in or an iterator
* @param string $whitelist Regex that matches against the file path
* *
* @return array A class map array * @return array A class map array
*/ */
public static function createMap($dir) public static function createMap($dir, $whitelist = null)
{ {
if (is_string($dir)) { if (is_string($dir)) {
if (is_file($dir)) { if (is_file($dir)) {
@ -67,6 +68,10 @@ class ClassMapGenerator
continue; continue;
} }
if ($whitelist && !preg_match($whitelist, strtr($path, '\\', '/'))) {
continue;
}
$classes = self::findClasses($path); $classes = self::findClasses($path);
foreach ($classes as $class) { foreach ($classes as $class) {