|
|
|
@ -255,7 +255,9 @@ class FileHelperTest extends TestCase
|
|
|
|
|
{ |
|
|
|
|
$basePath = $this->testFilePath . DIRECTORY_SEPARATOR; |
|
|
|
|
$dirs = ['', 'one', 'one' . DIRECTORY_SEPARATOR . 'two', 'three']; |
|
|
|
|
$files = array_fill_keys(array_map(function($n){return "a.$n";}, range(1,8)), 'file contents'); |
|
|
|
|
$files = array_fill_keys(array_map(function ($n) { |
|
|
|
|
return "a.$n"; |
|
|
|
|
}, range(1, 8)), 'file contents'); |
|
|
|
|
|
|
|
|
|
$tree = $files; |
|
|
|
|
$root = $files; |
|
|
|
@ -264,7 +266,9 @@ class FileHelperTest extends TestCase
|
|
|
|
|
foreach ($files as $fileName => $contents) { |
|
|
|
|
$flat[] = rtrim($basePath . $dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $fileName; |
|
|
|
|
} |
|
|
|
|
if ($dir === '') continue; |
|
|
|
|
if ($dir === '') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$parts = explode(DIRECTORY_SEPARATOR, $dir); |
|
|
|
|
$last = array_pop($parts); |
|
|
|
|
$parent = array_pop($parts); |
|
|
|
@ -280,19 +284,25 @@ class FileHelperTest extends TestCase
|
|
|
|
|
// range |
|
|
|
|
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]); |
|
|
|
|
sort($foundFiles); |
|
|
|
|
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)==='a.1';})); |
|
|
|
|
$expect = array_values(array_filter($flat, function ($p) { |
|
|
|
|
return substr($p, -3)==='a.1'; |
|
|
|
|
})); |
|
|
|
|
$this->assertEquals($expect, $foundFiles); |
|
|
|
|
|
|
|
|
|
// suffix |
|
|
|
|
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]); |
|
|
|
|
sort($foundFiles); |
|
|
|
|
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)!=='a.1';})); |
|
|
|
|
$expect = array_values(array_filter($flat, function ($p) { |
|
|
|
|
return substr($p, -3)!=='a.1'; |
|
|
|
|
})); |
|
|
|
|
$this->assertEquals($expect, $foundFiles); |
|
|
|
|
|
|
|
|
|
// dir |
|
|
|
|
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]); |
|
|
|
|
sort($foundFiles); |
|
|
|
|
$expect = array_values(array_filter($flat, function($p){return strpos($p, DIRECTORY_SEPARATOR.'one')===false;})); |
|
|
|
|
$expect = array_values(array_filter($flat, function ($p) { |
|
|
|
|
return strpos($p, DIRECTORY_SEPARATOR.'one')===false; |
|
|
|
|
})); |
|
|
|
|
$this->assertEquals($expect, $foundFiles); |
|
|
|
|
|
|
|
|
|
// dir contents |
|
|
|
|