given( $root = resolve('hoa://Test/Vfs/Root?type=directory'), resolve('hoa://Test/Vfs/Root/A?type=file'), resolve('hoa://Test/Vfs/Root/Aa?type=file'), resolve('hoa://Test/Vfs/Root/Aaa?type=file'), $iterator = new LUT\Directory($root), $result = [] ) ->when(function () use ($iterator, &$result) { foreach ($iterator as $key => $file) { $result[$key] = $file->getFilename(); $this ->object($file) ->isInstanceOf(LUT\Directory::class); } }) ->then ->array($result) ->isEqualTo([ 0 => 'A', 1 => 'Aa', 2 => 'Aaa' ]); } public function case_seek_and_dots() { $this ->given( $root = resolve('hoa://Test/Vfs/Root?type=directory'), resolve('hoa://Test/Vfs/Root/.?type=directory'), resolve('hoa://Test/Vfs/Root/..?type=directory'), resolve('hoa://Test/Vfs/Root/Skip?type=file'), resolve('hoa://Test/Vfs/Root/Gotcha?type=file'), $iterator = new LUT\Directory($root) ) ->when($result = $iterator->current()) ->then ->boolean($result->isDot()) ->isTrue() ->when( $iterator->next(), $result = $iterator->current() ) ->then ->boolean($result->isDot()) ->isTrue() ->when( $iterator->seek(3), $result = $iterator->current() ) ->then ->string($result->getFilename()) ->isEqualTo('Gotcha') ->when( $iterator->seek(2), $result = $iterator->current() ) ->then ->string($result->getFilename()) ->isEqualTo('Skip'); } public function case_recursive() { $this ->given( $root = resolve('hoa://Test/Vfs/Root?type=directory'), resolve('hoa://Test/Vfs/Root/A?type=file'), resolve('hoa://Test/Vfs/Root/Aa?type=file'), resolve('hoa://Test/Vfs/Root/Aaa?type=file'), resolve('hoa://Test/Vfs/Root/Foo?type=directory'), resolve('hoa://Test/Vfs/Root/Foo/Bar?type=directory'), resolve('hoa://Test/Vfs/Root/Foo/Bar/B?type=file'), resolve('hoa://Test/Vfs/Root/Foo/Bar/Bb?type=file'), resolve('hoa://Test/Vfs/Root/Foo/Bar/Bbb?type=file'), resolve('hoa://Test/Vfs/Root/Foo/C?type=file'), resolve('hoa://Test/Vfs/Root/Foo/Cc?type=file'), resolve('hoa://Test/Vfs/Root/Foo/Ccc?type=file'), $directory = new LUT\Recursive\Directory($root), $iterator = new LUT\Recursive\Iterator($directory), $result = [] ) ->when(function () use ($iterator, &$result) { foreach ($iterator as $file) { $result[] = $file->getFilename(); } }) ->then ->array($result) ->isEqualTo([ 'A', 'Aa', 'Aaa', 'B', 'Bb', 'Bbb', 'C', 'Cc', 'Ccc' ]); } public function case_splFileClassInfo() { $this ->given( $splFileInfo = 'Hoa\Iterator\SplFileInfo', $root = resolve('hoa://Test/Vfs/Root?type=directory'), resolve('hoa://Test/Vfs/Root/a?type=file'), resolve('hoa://Test/Vfs/Root/b?type=file'), resolve('hoa://Test/Vfs/Root/c?type=file'), resolve('hoa://Test/Vfs/Root/d?type=file'), resolve('hoa://Test/Vfs/Root/e?type=file'), resolve('hoa://Test/Vfs/Root/f?type=file'), $iterator = new LUT\Directory( $root, $splFileInfo ), $result = [] ) ->when(function () use ($iterator, $splFileInfo, &$result) { foreach ($iterator as $file) { $this ->object($file) ->isInstanceOf($splFileInfo); $result[] = $file->getFilename(); } }) ->then ->array($result) ->isEqualTo([ 'a', 'b', 'c', 'd', 'e', 'f' ]); } public function case_recursive_splFileClassInfo() { $this ->given( $splFileInfo = 'Hoa\Iterator\SplFileInfo', $root = resolve('hoa://Test/Vfs/Root?type=directory'), resolve('hoa://Test/Vfs/Root/A?type=directory'), resolve('hoa://Test/Vfs/Root/A/a?type=file'), resolve('hoa://Test/Vfs/Root/A/b?type=file'), resolve('hoa://Test/Vfs/Root/A/c?type=file'), resolve('hoa://Test/Vfs/Root/B?type=directory'), resolve('hoa://Test/Vfs/Root/B/d?type=file'), resolve('hoa://Test/Vfs/Root/B/e?type=file'), resolve('hoa://Test/Vfs/Root/B/c?type=directory'), resolve('hoa://Test/Vfs/Root/B/c/f?type=file'), $directory = new LUT\Recursive\Directory( $root, LUT\FileSystem::CURRENT_AS_FILEINFO, $splFileInfo ), $iterator = new LUT\Recursive\Iterator($directory), $result = [] ) ->when(function () use ($iterator, $splFileInfo, &$result) { foreach ($iterator as $file) { $this ->object($file) ->isInstanceOf($splFileInfo); $result[] = $file->getFilename(); } }) ->then ->array($result) ->isEqualTo([ 'a', 'b', 'c', 'd', 'e', 'f' ]); } }