1--TEST--
2Test fflush() function: error conditions
3--FILE--
4<?php
5/*
6 Prototype: bool fflush ( resource $handle );
7 Description: Flushes the output to a file
8*/
9
10echo "*** Testing error conditions ***\n";
11$file_path = dirname(__FILE__);
12
13// zero argument
14echo "-- Testing fflush(): with zero argument --\n";
15var_dump( fflush() );
16
17// more than expected no. of args
18echo "-- Testing fflush(): with more than expected number of arguments --\n";
19
20$filename = "$file_path/fflush_error.tmp";
21$file_handle = fopen($filename, "w");
22if($file_handle == false)
23  exit("Error:failed to open file $filename");
24
25var_dump( fflush($file_handle, $file_handle) );
26fclose($file_handle);
27
28// test invalid arguments : non-resources
29echo "-- Testing fflush(): with invalid arguments --\n";
30$invalid_args = array (
31  "string",
32  10,
33  10.5,
34  true,
35  array(1,2,3),
36  new stdclass
37);
38
39/* loop to test fflush() with different invalid type of args */
40for($loop_counter = 1; $loop_counter <= count($invalid_args); $loop_counter++) {
41  echo "-- Iteration $loop_counter --\n";
42  var_dump( fflush($invalid_args[$loop_counter - 1]) );
43}
44echo "\n*** Done ***";
45?>
46--CLEAN--
47<?php
48$file_path = dirname(__FILE__);
49unlink("$file_path/fflush_error.tmp");
50?>
51--EXPECTF--
52*** Testing error conditions ***
53-- Testing fflush(): with zero argument --
54
55Warning: fflush() expects exactly 1 parameter, 0 given in %s on line %d
56bool(false)
57-- Testing fflush(): with more than expected number of arguments --
58
59Warning: fflush() expects exactly 1 parameter, 2 given in %s on line %d
60bool(false)
61-- Testing fflush(): with invalid arguments --
62-- Iteration 1 --
63
64Warning: fflush() expects parameter 1 to be resource, string given in %s on line %d
65bool(false)
66-- Iteration 2 --
67
68Warning: fflush() expects parameter 1 to be resource, integer given in %s on line %d
69bool(false)
70-- Iteration 3 --
71
72Warning: fflush() expects parameter 1 to be resource, float given in %s on line %d
73bool(false)
74-- Iteration 4 --
75
76Warning: fflush() expects parameter 1 to be resource, boolean given in %s on line %d
77bool(false)
78-- Iteration 5 --
79
80Warning: fflush() expects parameter 1 to be resource, array given in %s on line %d
81bool(false)
82-- Iteration 6 --
83
84Warning: fflush() expects parameter 1 to be resource, object given in %s on line %d
85bool(false)
86
87*** Done ***
88