mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
add directory wrapper base
This commit is contained in:
parent
d31237bc40
commit
91176a6bf5
2 changed files with 143 additions and 0 deletions
40
tests/DirectoryWrapper.php
Normal file
40
tests/DirectoryWrapper.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Licensed under the MIT license:
|
||||
* http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Icewind\Streams\Tests;
|
||||
|
||||
class DirectoryWrapperDummy extends \Icewind\Streams\DirectoryWrapper {
|
||||
public function dir_readdir() {
|
||||
$file = parent::dir_readdir();
|
||||
if ($file !== false) {
|
||||
$file .= '_';
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
class DirectoryWrapper extends IteratorDirectory {
|
||||
|
||||
/**
|
||||
* @param \Iterator | array $source
|
||||
* @return resource
|
||||
*/
|
||||
protected function wrapSource($source) {
|
||||
$dir = \Icewind\Streams\IteratorDirectory::wrap($source);
|
||||
return \Icewind\Streams\DirectoryWrapper::wrap($dir);
|
||||
}
|
||||
|
||||
public function testManipulateContent() {
|
||||
$source = \Icewind\Streams\IteratorDirectory::wrap(['asd', 'bar']);
|
||||
$wrapped = DirectoryWrapperDummy::wrap($source);
|
||||
$result = [];
|
||||
while (($file = readdir($wrapped)) !== false) {
|
||||
$result[] = $file;
|
||||
}
|
||||
$this->assertEquals(['asd_', 'bar_'], $result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue