Merge pull request #10 from rullzer/master

Pass the strlen to the readCallback as was expected
This commit is contained in:
Robin Appelman 2019-02-15 13:57:29 +01:00 committed by GitHub
commit 4db3ed6c36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -97,7 +97,7 @@ class CallbackWrapper extends Wrapper {
public function stream_read($count) {
$result = parent::stream_read($count);
if (is_callable($this->readCallback)) {
call_user_func($this->readCallback, $result);
call_user_func($this->readCallback, strlen($result));
}
return $result;
}

View file

@ -31,8 +31,10 @@ class CallbackWrapperTest extends WrapperTest {
public function testReadCallback() {
$called = false;
$callBack = function () use (&$called) {
$bytesRead = 0;
$callBack = function ($count) use (&$called, &$bytesRead) {
$called = true;
$bytesRead += $count;
};
$source = fopen('php://temp', 'r+');
@ -42,6 +44,9 @@ class CallbackWrapperTest extends WrapperTest {
$wrapped = $this->wrapSource($source, $callBack);
$this->assertEquals('foo', fread($wrapped, 3));
$this->assertTrue($called);
$this->assertEquals('bar', fread($wrapped, 1000));
$this->assertEquals(6, $bytesRead);
}
public function testWriteCallback() {