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
47--CLEAN--
48<?php
49$file_path = dirname(__FILE__);
50unlink("$file_path/fflush_error.tmp");
51?>
52
53--EXPECTF--
54*** Testing error conditions ***
55-- Testing fflush(): with zero argument --
56
57Warning: fflush() expects exactly 1 parameter, 0 given in %s on line %d
58bool(false)
59-- Testing fflush(): with more than expected number of arguments --
60
61Warning: fflush() expects exactly 1 parameter, 2 given in %s on line %d
62bool(false)
63-- Testing fflush(): with invalid arguments --
64-- Iteration 1 --
65
66Warning: fflush() expects parameter 1 to be resource, string given in %s on line %d
67bool(false)
68-- Iteration 2 --
69
70Warning: fflush() expects parameter 1 to be resource, integer given in %s on line %d
71bool(false)
72-- Iteration 3 --
73
74Warning: fflush() expects parameter 1 to be resource, float given in %s on line %d
75bool(false)
76-- Iteration 4 --
77
78Warning: fflush() expects parameter 1 to be resource, boolean given in %s on line %d
79bool(false)
80-- Iteration 5 --
81
82Warning: fflush() expects parameter 1 to be resource, array given in %s on line %d
83bool(false)
84-- Iteration 6 --
85
86Warning: fflush() expects parameter 1 to be resource, object given in %s on line %d
87bool(false)
88
89*** Done ***
90
91