Merge branch 'develop-ascraeus' into develop

* develop-ascraeus:
  [ticket/12589] Add test searching in a non absolute directory
  [ticket/12589] Fix tests
  [ticket/12589] Search directly in $directory if it's an absolute sub-path
This commit is contained in:
Joas Schilling 2014-05-31 01:35:23 +02:00
commit 93c310f66b
2 changed files with 65 additions and 34 deletions

View file

@ -465,6 +465,10 @@ class finder
}
else if ($directory && $directory[0] === '/')
{
if (!$is_dir)
{
$path .= substr($directory, 1);
}
$directory_pattern = '^' . preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#');
}
else
@ -477,6 +481,8 @@ class finder
}
$directory_pattern = '#' . $directory_pattern . '#';
if (is_dir($path))
{
$iterator = new \RecursiveIteratorIterator(
new \phpbb\recursive_dot_prefix_filter_iterator(
new \RecursiveDirectoryIterator(
@ -503,7 +509,15 @@ class finder
}
else
{
$relative_path = DIRECTORY_SEPARATOR . $iterator->getInnerIterator()->getSubPathname();
$relative_path = $iterator->getInnerIterator()->getSubPathname();
if ($directory && $directory[0] === '/')
{
$relative_path = str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR . $relative_path;
}
else
{
$relative_path = DIRECTORY_SEPARATOR . $relative_path;
}
}
if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) &&
@ -520,6 +534,7 @@ class finder
}
}
}
}
if ($cache && $this->cache)
{

View file

@ -132,6 +132,22 @@ class phpbb_extension_finder_test extends phpbb_test_case
);
}
public function test_non_absolute_directory_get_classes()
{
$classes = $this->finder
->directory('type/')
->get_classes();
sort($classes);
$this->assertEquals(
array(
'\vendor2\foo\sub\type\alternative',
'\vendor2\foo\type\alternative',
),
$classes
);
}
public function test_sub_directory_get_classes()
{
$classes = $this->finder