mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
Add directory support to wrappers
This commit is contained in:
parent
448dfc577c
commit
53cfe7f4f1
5 changed files with 121 additions and 28 deletions
|
|
@ -14,10 +14,11 @@ class CallbackWrapper extends Wrapper {
|
|||
* @param callable $read
|
||||
* @param callable $write
|
||||
* @param callable $close
|
||||
* @param callable $readDir
|
||||
* @return resource
|
||||
*/
|
||||
protected function wrapSource($source, $read = null, $write = null, $close = null) {
|
||||
return \Icewind\Streams\CallbackWrapper::wrap($source, $read, $write, $close);
|
||||
protected function wrapSource($source, $read = null, $write = null, $close = null, $readDir = null) {
|
||||
return \Icewind\Streams\CallbackWrapper::wrap($source, $read, $write, $close, $readDir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,4 +70,17 @@ class CallbackWrapper extends Wrapper {
|
|||
fclose($wrapped);
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testReadDirCallback() {
|
||||
$called = false;
|
||||
$callBack = function () use (&$called) {
|
||||
$called = true;
|
||||
};
|
||||
|
||||
$source = opendir(sys_get_temp_dir());
|
||||
|
||||
$wrapped = $this->wrapSource($source, null, null, null, $callBack);
|
||||
readdir($wrapped);
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,4 +102,38 @@ abstract class Wrapper extends \PHPUnit_Framework_TestCase {
|
|||
stream_set_timeout($wrapped, 1, 0);
|
||||
stream_set_write_buffer($wrapped, 0);
|
||||
}
|
||||
|
||||
public function testReadDir() {
|
||||
$source = opendir(__DIR__);
|
||||
$content = array();
|
||||
while (($name = readdir($source)) !== false) {
|
||||
$content[] = $name;
|
||||
}
|
||||
closedir($source);
|
||||
|
||||
$source = opendir(__DIR__);
|
||||
$wrapped = $this->wrapSource($source);
|
||||
$wrappedContent = array();
|
||||
while (($name = readdir($wrapped)) !== false) {
|
||||
$wrappedContent[] = $name;
|
||||
}
|
||||
$this->assertEquals($content, $wrappedContent);
|
||||
}
|
||||
|
||||
public function testRewindDir() {
|
||||
$source = opendir(__DIR__);
|
||||
$content = array();
|
||||
while (($name = readdir($source)) !== false) {
|
||||
$content[] = $name;
|
||||
}
|
||||
closedir($source);
|
||||
|
||||
$source = opendir(__DIR__);
|
||||
$wrapped = $this->wrapSource($source);
|
||||
$this->assertEquals($content[0], readdir($wrapped));
|
||||
$this->assertEquals($content[1], readdir($wrapped));
|
||||
$this->assertEquals($content[2], readdir($wrapped));
|
||||
rewinddir($wrapped);
|
||||
$this->assertEquals($content[0], readdir($wrapped));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue