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    try {
26        var_dump(stream_select($r, $w, $e, 0) !== false);
27    } catch (TypeError|ValueError $e) {
28        echo $e->getMessage(), "\n";
29    }
30}
31
32var_dump(stream_wrapper_register('test', 'test_wrapper'));
33var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
34
35$fd = fopen("test://foo","r");
36$fd2 = fopen("test2://foo","r");
37
38test("valid stream", $fd, STDIN);
39test("stream_cast not implemented", $fd2, null);
40test("return value is false", $fd, false);
41test("return value not a stream resource", $fd, "foo");
42test("return value is stream itself", $fd, $fd);
43test("return value cannot be casted", $fd, $fd2);
44
45?>
46--EXPECTF--
47bool(true)
48bool(true)
49
50------ valid stream: -------
51bool(true)
52
53------ stream_cast not implemented: -------
54
55Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
56
57Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
58No stream arrays were passed
59
60------ return value is false: -------
61
62Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
63No stream arrays were passed
64
65------ return value not a stream resource: -------
66
67Warning: stream_select(): test_wrapper::stream_cast must return a stream resource in %s
68
69Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
70No stream arrays were passed
71
72------ return value is stream itself: -------
73
74Warning: stream_select(): test_wrapper::stream_cast must not return itself in %s
75
76Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
77No stream arrays were passed
78
79------ return value cannot be casted: -------
80
81Warning: stream_select(): test_wrapper_base::stream_cast is not implemented! in %s
82
83Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
84
85Warning: stream_select(): Cannot represent a stream of type user-space as a select()able descriptor in %s
86No stream arrays were passed
87