3 declare(strict_types=1);
33 $fileSystem = $this->getMockBuilder(
Filesystem\Filesystem::class)->getMock();
36 new Filesystem\DTO\Metadata(
'file_1.txt', MetadataType::FILE),
37 new Filesystem\DTO\Metadata(
'file_2.mp3', MetadataType::FILE),
38 new Filesystem\DTO\Metadata(
'dir_1', MetadataType::DIRECTORY),
42 ->expects($this->atLeast(1))
43 ->method(
'listContents')
44 ->willReturnCallback(
function (
$path) use ($metadata) {
61 $fileSystem = $this->getMockBuilder(
Filesystem\Filesystem::class)->getMock();
64 new Filesystem\DTO\Metadata(
'file_1.txt', MetadataType::FILE),
65 new Filesystem\DTO\Metadata(
'file_2.mp3', MetadataType::FILE),
66 new Filesystem\DTO\Metadata(
'dir_1', MetadataType::DIRECTORY),
70 new Filesystem\DTO\Metadata(
'dir_1/file_3.log', MetadataType::FILE),
71 new Filesystem\DTO\Metadata(
'dir_1/file_4.php', MetadataType::FILE),
72 new Filesystem\DTO\Metadata(
'dir_1/dir_1_1', MetadataType::DIRECTORY),
73 new Filesystem\DTO\Metadata(
'dir_1/dir_1_2', MetadataType::DIRECTORY),
77 new Filesystem\DTO\Metadata(
'dir_1/dir_1_1/file_5.cpp', MetadataType::FILE),
81 new Filesystem\DTO\Metadata(
'dir_1/dir_1_2/file_6.py', MetadataType::FILE),
82 new Filesystem\DTO\Metadata(
'dir_1/dir_1_2/file_7.cpp', MetadataType::FILE),
83 new Filesystem\DTO\Metadata(
'dir_1/dir_1_2/dir_1_2_1', MetadataType::DIRECTORY),
87 ->expects($this->atLeast(1))
88 ->method(
'listContents')
89 ->willReturnCallback(
function (
$path) use (
97 } elseif (
'dir_1' ===
$path) {
98 return $level1Metadata;
99 } elseif (
'dir_1/dir_1_1' ===
$path) {
100 return $level11Metadata;
101 } elseif (
'dir_1/dir_1_2' ===
$path) {
102 return $level12Metadata;
116 $fileSystem = $this->getMockBuilder(
Filesystem\Filesystem::class)->getMock();
119 ->method(
'listContents')
122 $finder = (
new Finder($fileSystem))->in([
'/']);
124 $this->assertEmpty(iterator_count($finder));
134 $this->assertCount(3, $finder);
135 $this->assertCount(1, $finder->directories());
136 $this->assertCount(2, $finder->files());
146 $this->assertCount(11, $finder);
147 $this->assertCount(4, $finder->directories());
148 $this->assertCount(7, $finder->files());
158 $level0Finder = $finder->depth(0);
159 $this->assertCount(3, $level0Finder);
160 $this->assertCount(1, $level0Finder->directories());
161 $this->assertCount(2, $level0Finder->files());
163 $greaterLevel0Finder = $finder->depth(
'> 0');
164 $this->assertCount(8, $greaterLevel0Finder);
165 $this->assertCount(3, $greaterLevel0Finder->directories());
166 $this->assertCount(5, $greaterLevel0Finder->files());
168 $greaterOrEqualLevel0Finder = $finder->depth(
'>= 0');
169 $this->assertCount(11, $greaterOrEqualLevel0Finder);
170 $this->assertCount(4, $greaterOrEqualLevel0Finder->directories());
171 $this->assertCount(7, $greaterOrEqualLevel0Finder->files());
173 $lowerOrEqualLevel1Finder = $finder->depth(
'<= 1');
174 $this->assertCount(7, $lowerOrEqualLevel1Finder);
175 $this->assertCount(3, $lowerOrEqualLevel1Finder->directories());
176 $this->assertCount(4, $lowerOrEqualLevel1Finder->files());
178 $lowerLevel2Finder = $finder->depth(
'< 2');
179 $this->assertCount(7, $lowerLevel2Finder);
180 $this->assertCount(3, $lowerLevel2Finder->directories());
181 $this->assertCount(4, $lowerLevel2Finder->files());
183 $exactlyLevel2Finder = $finder->depth(2);
184 $this->assertCount(4, $exactlyLevel2Finder);
185 $this->assertCount(1, $exactlyLevel2Finder->directories());
186 $this->assertCount(3, $exactlyLevel2Finder->files());
196 $finderWithExcludedDir = $finder->exclude([
'dir_1/dir_1_1']);
197 $this->assertCount(9, $finderWithExcludedDir);
198 $this->assertCount(3, $finderWithExcludedDir->directories());
199 $this->assertCount(6, $finderWithExcludedDir->files());
201 $finderWithMultipleExcludedDirs = $finder->exclude([
'dir_1/dir_1_1',
'dir_1/dir_1_2/dir_1_2_1']);
202 $this->assertCount(8, $finderWithMultipleExcludedDirs);
203 $this->assertCount(2, $finderWithMultipleExcludedDirs->directories());
204 $this->assertCount(6, $finderWithMultipleExcludedDirs->files());
213 $now = new \DateTimeImmutable(
'2019-03-30 13:00:00');
216 $fs->method(
'has')->willReturn(
true);
219 ->expects($this->atLeast(1))
220 ->method(
'getTimestamp')
227 return $now->modify(
'+1 hour');
229 case 'dir_1/file_3.log':
230 return $now->modify(
'+2 hour');
232 case 'dir_1/file_4.php':
233 return $now->modify(
'+3 hour');
235 case 'dir_1/dir_1_1/file_5.cpp':
236 return $now->modify(
'+4 hour');
238 case 'dir_1/dir_1_2/file_6.py':
239 return $now->modify(
'+5 hour');
241 case 'dir_1/dir_1_2/file_7.cpp':
242 return $now->modify(
'+6 hour');
245 return new \DateTimeImmutable(
'now');
249 $finder = (
new Finder($fs))->in([
'/']);
251 for (
$i = 1;
$i <= 7;
$i++) {
252 $this->assertCount(8 -
$i, $finder->date(
'>= 2019-03-30 1' . (
string) (2 +
$i) .
':00')->files());
254 $this->assertCount(3, $finder->date(
'>= 2019-03-30 15:00 + 2hours')->files());
255 $this->assertCount(2, $finder->date(
'> 2019-03-30 15:00 + 2hours')->files());
256 $this->assertCount(1, $finder->date(
'2019-03-30 15:00 + 2hours')->files());
257 $this->assertCount(2, $finder->date(
'< 2019-03-30 15:00')->files());
258 $this->assertCount(3, $finder->date(
'<= 2019-03-30 15:00')->files());
259 $this->assertCount(2, $finder->date(
'<= 2019-03-30 15:00 - 1minute')->files());
270 $fs->method(
'has')->willReturn(
true);
272 $fs->expects($this->atLeast(1))
277 return new DataSize(PHP_INT_MAX, DataSize::Byte);
280 return new DataSize(1024, DataSize::Byte);
282 case 'dir_1/file_3.log':
283 return new DataSize(1024 * 1024 * 1024, DataSize::Byte);
285 case 'dir_1/file_4.php':
286 return new DataSize(1024 * 1024 * 127, DataSize::Byte);
288 case 'dir_1/dir_1_1/file_5.cpp':
289 return new DataSize(1024 * 7, DataSize::Byte);
291 case 'dir_1/dir_1_2/file_6.py':
292 return new DataSize(1024 * 100, DataSize::Byte);
294 case 'dir_1/dir_1_2/file_7.cpp':
295 return new DataSize(1, DataSize::Byte);
298 return new DataSize(0, DataSize::Byte);
302 $finder = (
new Finder($fs))->in([
'/']);
304 $this->assertCount(1, $finder->size(
'< 1Ki')->files());
305 $this->assertCount(2, $finder->size(
'<= 1Ki')->files());
306 $this->assertCount(6, $finder->size(
'>= 1Ki')->files());
307 $this->assertCount(5, $finder->size(
'> 1Ki')->files());
308 $this->assertCount(1, $finder->size(
'1Ki')->files());
310 $this->assertCount(3, $finder->size(
'> 1Mi')->files());
311 $this->assertCount(2, $finder->size(
'>= 1Gi')->files());
320 $finder = (
new Finder($fs))->in([
'/']);
322 $this->assertEquals(
'file_1.txt', $finder->files()->sortByTime()->getIterator()->current()->getPath());
324 'dir_1/dir_1_2/file_7.cpp',
325 $finder->files()->sortByTime()->reverseSorting()->getIterator()->current()->getPath()
328 $this->assertEquals(
'dir_1', $finder->sortByName()->getIterator()->current()->getPath());
329 $this->assertEquals(
'file_2.mp3', $finder->sortByName()->reverseSorting()->getIterator()->current()->getPath());
331 $this->assertEquals(
'dir_1', $finder->sortByType()->getIterator()->current()->getPath());
332 $this->assertEquals(
'file_2.mp3', $finder->sortByType()->reverseSorting()->getIterator()->current()->getPath());
335 if (
'dir_1/dir_1_1/file_5.cpp' === $left->getPath()) {
341 $this->assertEquals(
'dir_1/dir_1_1/file_5.cpp', $customSortFinder->getIterator()->current()->getPath());
342 $all = array_values(iterator_to_array($customSortFinder->reverseSorting()->getIterator()));
343 $last = $all[iterator_count($customSortFinder) - 1];
344 $this->assertEquals(
'dir_1/dir_1_1/file_5.cpp', $last->getPath());
getFlatFileSystemStructure()
testFinderWillFindFilesAndFoldersInFlatStructure()
testSortingWorksAsExpected(Filesystem\Filesystem $fs)
Class ChatMainBarProvider .
This class provides the data size with additional information to remove the work to calculate the siz...
getNestedFileSystemStructure()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testFinderWillFindNoFilesOrFoldersInAnEmptyDirectory()
testFinderWillFilterFilesAndFoldersByCreationTimestamp()
testFinderWillFindFilesAndFoldersInNestedStructure()
testFinderWillFindFilesAndFoldersForACertainDirectoryDepth()
testFinderWillFilterFilesBySize()
Class FlySystemFileAccessTest disabled disabled disabled.
testFinderWillNotSearchInExcludedFolders()