1--TEST-- 2User-space streams: stream_set_option() 3--FILE-- 4<?php 5class test_wrapper_base { 6 public $return_value; 7 public $expected_option; 8 public $expected_value; 9 function stream_open($path, $mode, $openedpath) { 10 return true; 11 } 12 function stream_eof() { 13 return false; 14 } 15} 16class test_wrapper extends test_wrapper_base { 17 function stream_set_option($option, $value, $ptrparam) { 18 echo "value:\n"; 19 var_dump($value); 20 echo "ptrparam:\n"; 21 var_dump($ptrparam); 22 echo "\$option === $option === " . $this->expected_option . ":\n";; 23 var_dump($option === $this->expected_option); 24 echo "\$value === $value === " . $this->expected_value. ":\n";; 25 var_dump($value === $this->expected_value); 26 return $this->return_value; 27 } 28} 29 30function test($name, $fd, $return_value, $func, $args, $expected_option, $expected_value) { 31 echo "\n------ $name: -------\n"; 32 $data = stream_get_meta_data($fd); 33 $data['wrapper_data']->return_value = $return_value; 34 $data['wrapper_data']->expected_option = $expected_option; 35 $data['wrapper_data']->expected_value = $expected_value; 36 var_dump(call_user_func_array($func, $args)); 37} 38 39var_dump(stream_wrapper_register('test', 'test_wrapper')); 40var_dump(stream_wrapper_register('test2', 'test_wrapper_base')); 41 42$fd = fopen("test://foo","r"); 43$fd2 = fopen("test2://foo","r"); 44 45test("stream_set_blocking - 1", $fd, true, "stream_set_blocking", array($fd,0), STREAM_OPTION_BLOCKING, 0); 46test("stream_set_blocking - 2", $fd, false, "stream_set_blocking", array($fd,1), STREAM_OPTION_BLOCKING, 1); 47test("stream_set_blocking - 3", $fd, "foo", "stream_set_blocking", array($fd,0), STREAM_OPTION_BLOCKING, 0); 48test("stream_set_blocking - 4", $fd2, true, "stream_set_blocking", array($fd2,1), STREAM_OPTION_BLOCKING, 1); 49 50test("stream_set_write_buffer - 1", $fd, true, "stream_set_write_buffer", array($fd,0), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_NONE); 51test("stream_set_write_buffer - 2", $fd, true, "stream_set_write_buffer", array($fd,4096), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_FULL); 52test("stream_set_write_buffer - 3", $fd, false, "stream_set_write_buffer", array($fd,8192), STREAM_OPTION_WRITE_BUFFER, STREAM_BUFFER_FULL); 53 54test("stream_set_timeout - 1", $fd, true, "stream_set_timeout", array($fd,10,11), STREAM_OPTION_READ_TIMEOUT, 10); 55test("stream_set_timeout - 2", $fd, false, "stream_set_timeout", array($fd,11,12), STREAM_OPTION_READ_TIMEOUT, 11); 56 57?> 58--EXPECTF-- 59bool(true) 60bool(true) 61 62------ stream_set_blocking - 1: ------- 63value: 64int(0) 65ptrparam: 66NULL 67$option === 1 === 1: 68bool(true) 69$value === 0 === 0: 70bool(true) 71bool(true) 72 73------ stream_set_blocking - 2: ------- 74value: 75int(1) 76ptrparam: 77NULL 78$option === 1 === 1: 79bool(true) 80$value === 1 === 1: 81bool(true) 82bool(false) 83 84------ stream_set_blocking - 3: ------- 85value: 86int(0) 87ptrparam: 88NULL 89$option === 1 === 1: 90bool(true) 91$value === 0 === 0: 92bool(true) 93bool(true) 94 95------ stream_set_blocking - 4: ------- 96 97Warning: stream_set_blocking(): test_wrapper_base::stream_set_option is not implemented! in %s 98bool(false) 99 100------ stream_set_write_buffer - 1: ------- 101value: 102int(0) 103ptrparam: 104int(%d) 105$option === 3 === 3: 106bool(true) 107$value === 0 === 0: 108bool(true) 109int(0) 110 111------ stream_set_write_buffer - 2: ------- 112value: 113int(2) 114ptrparam: 115int(4096) 116$option === 3 === 3: 117bool(true) 118$value === 2 === 2: 119bool(true) 120int(0) 121 122------ stream_set_write_buffer - 3: ------- 123value: 124int(2) 125ptrparam: 126int(8192) 127$option === 3 === 3: 128bool(true) 129$value === 2 === 2: 130bool(true) 131int(-1) 132 133------ stream_set_timeout - 1: ------- 134value: 135int(10) 136ptrparam: 137int(11) 138$option === 4 === 4: 139bool(true) 140$value === 10 === 10: 141bool(true) 142bool(true) 143 144------ stream_set_timeout - 2: ------- 145value: 146int(11) 147ptrparam: 148int(12) 149$option === 4 === 4: 150bool(true) 151$value === 11 === 11: 152bool(true) 153bool(false) 154