mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 16:44:07 +02:00
Pass the strlen to the readCallback as was expected
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
e1b5ac12e9
commit
8c45c9a43b
2 changed files with 7 additions and 2 deletions
|
|
@ -97,7 +97,7 @@ class CallbackWrapper extends Wrapper {
|
||||||
public function stream_read($count) {
|
public function stream_read($count) {
|
||||||
$result = parent::stream_read($count);
|
$result = parent::stream_read($count);
|
||||||
if (is_callable($this->readCallback)) {
|
if (is_callable($this->readCallback)) {
|
||||||
call_user_func($this->readCallback, $result);
|
call_user_func($this->readCallback, strlen($result));
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,10 @@ class CallbackWrapperTest extends WrapperTest {
|
||||||
|
|
||||||
public function testReadCallback() {
|
public function testReadCallback() {
|
||||||
$called = false;
|
$called = false;
|
||||||
$callBack = function () use (&$called) {
|
$bytesRead = 0;
|
||||||
|
$callBack = function ($count) use (&$called, &$bytesRead) {
|
||||||
$called = true;
|
$called = true;
|
||||||
|
$bytesRead += $count;
|
||||||
};
|
};
|
||||||
|
|
||||||
$source = fopen('php://temp', 'r+');
|
$source = fopen('php://temp', 'r+');
|
||||||
|
|
@ -42,6 +44,9 @@ class CallbackWrapperTest extends WrapperTest {
|
||||||
$wrapped = $this->wrapSource($source, $callBack);
|
$wrapped = $this->wrapSource($source, $callBack);
|
||||||
$this->assertEquals('foo', fread($wrapped, 3));
|
$this->assertEquals('foo', fread($wrapped, 3));
|
||||||
$this->assertTrue($called);
|
$this->assertTrue($called);
|
||||||
|
|
||||||
|
$this->assertEquals('bar', fread($wrapped, 1000));
|
||||||
|
$this->assertEquals(6, $bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWriteCallback() {
|
public function testWriteCallback() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue