1--TEST--
2Test flock() function: Error conditions
3--FILE--
4<?php
5/*
6Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]);
7Description: PHP supports a portable way of locking complete files
8  in an advisory way
9*/
10
11echo "*** Testing error conditions ***\n";
12
13$file = dirname(__FILE__)."/flock.tmp";
14$fp = fopen($file, "w");
15
16/* array of operatons */
17$operations = array(
18  0,
19  LOCK_NB,
20  FALSE,
21  NULL,
22  array(1,2,3),
23  array(),
24  "string",
25  "",
26  "\0"
27);
28
29$i = 0;
30foreach($operations as $operation) {
31  echo "\n--- Iteration $i ---";
32  var_dump(flock($fp, $operation));
33  $i++;
34}
35
36
37/* Invalid arguments */
38$fp = fopen($file, "w");
39fclose($fp);
40var_dump(flock($fp, LOCK_SH|LOCK_NB));
41
42var_dump(flock("", "", $var));
43
44/* No.of args leass than expected */
45var_dump(flock());
46var_dump(flock($fp));
47
48/* No.of args greater than expected */
49var_dump(flock($fp, "", $var, ""));
50
51echo "\n*** Done ***\n";
52?>
53--CLEAN--
54<?php
55$file = dirname(__FILE__)."/flock.tmp";
56unlink($file);
57?>
58--EXPECTF--
59*** Testing error conditions ***
60
61--- Iteration 0 ---
62Warning: flock(): Illegal operation argument in %s on line %d
63bool(false)
64
65--- Iteration 1 ---
66Warning: flock(): Illegal operation argument in %s on line %d
67bool(false)
68
69--- Iteration 2 ---
70Warning: flock(): Illegal operation argument in %s on line %d
71bool(false)
72
73--- Iteration 3 ---
74Warning: flock(): Illegal operation argument in %s on line %d
75bool(false)
76
77--- Iteration 4 ---
78Warning: flock() expects parameter 2 to be long, array given in %s on line %d
79NULL
80
81--- Iteration 5 ---
82Warning: flock() expects parameter 2 to be long, array given in %s on line %d
83NULL
84
85--- Iteration 6 ---
86Warning: flock() expects parameter 2 to be long, string given in %s on line %d
87NULL
88
89--- Iteration 7 ---
90Warning: flock() expects parameter 2 to be long, string given in %s on line %d
91NULL
92
93--- Iteration 8 ---
94Warning: flock() expects parameter 2 to be long, string given in %s on line %d
95NULL
96
97Warning: flock(): %d is not a valid stream resource in %s on line %d
98bool(false)
99
100Warning: flock() expects parameter 1 to be resource, string given in %s on line %d
101NULL
102
103Warning: flock() expects at least 2 parameters, 0 given in %s on line %d
104NULL
105
106Warning: flock() expects at least 2 parameters, 1 given in %s on line %d
107NULL
108
109Warning: flock() expects at most 3 parameters, 4 given in %s on line %d
110NULL
111
112*** Done ***
113