1--TEST-- 2stream_set_chunk_size basic tests 3--FILE-- 4<?php 5class test_wrapper { 6 public $context; 7 function stream_open($path, $mode, $openedpath) { 8 return true; 9 } 10 function stream_eof() { 11 return false; 12 } 13 function stream_read($count) { 14 echo "read with size: ", $count, "\n"; 15 return str_repeat('a', $count); 16 } 17 function stream_write($data) { 18 echo "write with size: ", strlen($data), "\n"; 19 return strlen($data); 20 } 21 function stream_set_option($option, $arg1, $arg2) { 22 echo "option: ", $option, ", ", $arg1, ", ", $arg2, "\n"; 23 return false; 24 } 25} 26 27var_dump(stream_wrapper_register('test', 'test_wrapper')); 28 29$f = fopen("test://foo","r"); 30 31/* when the chunk size is 1, the read buffer is skipped, but the 32 * the writes are made in chunks of size 1 (business as usual) 33 * This should probably be revisited */ 34echo "should return previous chunk size (8192)\n"; 35var_dump(stream_set_chunk_size($f, 1)); 36echo "should be read without buffer (\$count == 10000)\n"; 37var_dump(strlen(fread($f, 10000))); 38echo "should elicit 3 writes\n"; 39var_dump(fwrite($f, str_repeat('b', 3))); 40 41echo "should return previous chunk size (1)\n"; 42var_dump(stream_set_chunk_size($f, 100)); 43echo "should elicit one read of size 100 (chunk size)\n"; 44var_dump(strlen(fread($f, 250))); 45echo "should elicit one read of size 100 (chunk size)\n"; 46var_dump(strlen(fread($f, 50))); 47echo "should elicit no read because there is sufficient cached data\n"; 48var_dump(strlen(fread($f, 50))); 49echo "should elicit 3 writes\n"; 50var_dump(strlen(fwrite($f, str_repeat('b', 250)))); 51 52echo "\nerror conditions\n"; 53try { 54 stream_set_chunk_size($f, 0); 55} catch (ValueError $exception) { 56 echo $exception->getMessage() . "\n"; 57} 58try { 59 stream_set_chunk_size($f, -1); 60} catch (ValueError $exception) { 61 echo $exception->getMessage() . "\n"; 62} 63?> 64--EXPECT-- 65bool(true) 66should return previous chunk size (8192) 67int(8192) 68should be read without buffer ($count == 10000) 69read with size: 10000 70int(10000) 71should elicit 3 writes 72write with size: 1 73write with size: 1 74write with size: 1 75int(3) 76should return previous chunk size (1) 77int(1) 78should elicit one read of size 100 (chunk size) 79read with size: 100 80int(100) 81should elicit one read of size 100 (chunk size) 82read with size: 100 83int(50) 84should elicit no read because there is sufficient cached data 85int(50) 86should elicit 3 writes 87write with size: 100 88write with size: 100 89write with size: 50 90int(3) 91 92error conditions 93stream_set_chunk_size(): Argument #2 ($size) must be greater than 0 94stream_set_chunk_size(): Argument #2 ($size) must be greater than 0 95