1--TEST--
2User-space streams: stream_lock()
3--FILE--
4<?php
5class test_wrapper_base {
6	public $mode;
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_lock($mode) {
16		$this->mode = $mode;
17	}
18}
19function test($name, $fd, $mode) {
20	echo "------ $name: -------\n";
21	flock($fd, $mode);
22	$data = stream_get_meta_data($fd);
23	var_dump($data['wrapper_data']->mode === $mode);
24}
25
26var_dump(stream_wrapper_register('test', 'test_wrapper'));
27var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
28
29$fd = fopen("test://foo","r");
30$fd2 = fopen("test2://foo","r");
31
32test("stream_lock not implemented", $fd2, LOCK_EX);
33
34foreach(array("LOCK_SH","LOCK_EX","LOCK_UN") as $mode) {
35	test("fclock($mode)", $fd, constant($mode));
36	test("fclock($mode|LOCK_NB)", $fd, constant($mode)|LOCK_NB);
37}
38
39?>
40--EXPECTF--
41bool(true)
42bool(true)
43------ stream_lock not implemented: -------
44
45Warning: flock(): test_wrapper_base::stream_lock is not implemented! in %s
46bool(false)
47------ fclock(LOCK_SH): -------
48bool(true)
49------ fclock(LOCK_SH|LOCK_NB): -------
50bool(true)
51------ fclock(LOCK_EX): -------
52bool(true)
53------ fclock(LOCK_EX|LOCK_NB): -------
54bool(true)
55------ fclock(LOCK_UN): -------
56bool(true)
57------ fclock(LOCK_UN|LOCK_NB): -------
58bool(true)
59