1--TEST--
2User-space streams: stream_cast()
3--FILE--
4<?php
5class test_wrapper_base {
6	public $return_value;
7	function stream_open($path, $mode, $openedpath) {
8		return true;
9	}
10	function stream_eof() {
11		return false;
12	}
13}
14class test_wrapper extends test_wrapper_base {
15	function stream_cast($castas) {
16		return $this->return_value;
17	}
18}
19function test($name, $fd, $return_value) {
20	echo "\n------ $name: -------\n";
21	$data = stream_get_meta_data($fd);
22	$data['wrapper_data']->return_value = $return_value;
23	$r = array($fd);
24	$w = $e = null;
25	var_dump(stream_select($r, $w, $e, 0) !== false);
26}
27
28var_dump(stream_wrapper_register('test', 'test_wrapper'));
29var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
30
31$fd = fopen("test://foo","r");
32$fd2 = fopen("test2://foo","r");
33
34test("valid stream", $fd, STDIN);
35test("stream_cast not implemented", $fd2, null);
36test("return value is false", $fd, false);
37test("return value not a stream resource", $fd, "foo");
38test("return value is stream itself", $fd, $fd);
39test("return value cannot be casted", $fd, $fd2);
40
41?>
42--EXPECTF--
43bool(true)
44bool(true)
45
46------ valid stream: -------
47bool(true)
48
49------ stream_cast not implemented: -------
50
51Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
52
53Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
54
55Warning: stream_select(): No stream arrays were passed in %s
56bool(false)
57
58------ return value is false: -------
59
60Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
61
62Warning: stream_select(): No stream arrays were passed in %s
63bool(false)
64
65------ return value not a stream resource: -------
66
67Warning: stream_select(): supplied argument is not a valid stream resource in %s
68
69Warning: stream_select(): test_wrapper::stream_cast must return a stream resource in %s
70
71Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
72
73Warning: stream_select(): No stream arrays were passed in %s
74bool(false)
75
76------ return value is stream itself: -------
77
78Warning: stream_select(): test_wrapper::stream_cast must not return itself in %s
79
80Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
81
82Warning: stream_select(): No stream arrays were passed in %s
83bool(false)
84
85------ return value cannot be casted: -------
86
87Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
88
89Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
90
91Warning: stream_select(): cannot represent a stream of type user-space as a select()able descriptor in %s
92
93Warning: stream_select(): No stream arrays were passed in %s
94bool(false)
95