1--TEST--
2Test rename() function : usage variation - different types for context
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7/* Prototype  : bool rename(string old_name, string new_name[, resource context])
8 * Description: Rename a file
9 * Source code: ext/standard/file.c
10 * Alias to functions:
11 */
12
13echo "*** Testing rename() : usage variation ***\n";
14
15// Define error handler
16function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
17	if (error_reporting() != 0) {
18		// report non-silenced errors
19		echo "Error: $err_no - $err_msg, $filename($linenum)\n";
20	}
21}
22set_error_handler('test_error_handler');
23
24// Initialise function arguments not being substituted (if any)
25$old_name = __FILE__.'.tmp';
26$new_name = __FILE__.'.renamed';
27
28//file resource
29$fileRes = fopen(__FILE__, 'r');
30
31//get an unset variable
32$unset_var = 10;
33unset ($unset_var);
34
35// define some classes
36class classWithToString
37{
38	public function __toString() {
39		return "Class A object";
40	}
41}
42
43class classWithoutToString
44{
45}
46
47// heredoc string
48$heredoc = <<<EOT
49hello world
50EOT;
51
52// add arrays
53$index_array = array (1, 2, 3);
54$assoc_array = array ('one' => 1, 'two' => 2);
55
56//array of values to iterate over
57$inputs = array(
58
59      // int data
60      'int 0' => 0,
61      'int 1' => 1,
62      'int 12345' => 12345,
63      'int -12345' => -2345,
64
65      // float data
66      'float 10.5' => 10.5,
67      'float -10.5' => -10.5,
68      'float 12.3456789000e10' => 12.3456789000e10,
69      'float -12.3456789000e10' => -12.3456789000e10,
70      'float .5' => .5,
71
72      // array data
73      'empty array' => array(),
74      'int indexed array' => $index_array,
75      'associative array' => $assoc_array,
76      'nested arrays' => array('foo', $index_array, $assoc_array),
77
78      // null data
79      'uppercase NULL' => NULL,
80      'lowercase null' => null,
81
82      // boolean data
83      'lowercase true' => true,
84      'lowercase false' =>false,
85      'uppercase TRUE' =>TRUE,
86      'uppercase FALSE' =>FALSE,
87
88      // empty data
89      'empty string DQ' => "",
90      'empty string SQ' => '',
91
92      // string data
93      'string DQ' => "string",
94      'string SQ' => 'string',
95      'mixed case string' => "sTrInG",
96      'heredoc' => $heredoc,
97
98      // object data
99      'instance of classWithToString' => new classWithToString(),
100      'instance of classWithoutToString' => new classWithoutToString(),
101
102      // undefined data
103      'undefined var' => @$undefined_var,
104
105      // unset data
106      'unset var' => @$unset_var,
107
108      // file resource
109      'file resource' => $fileRes,
110);
111
112// loop through each element of the array for context
113
114foreach($inputs as $key =>$value) {
115      echo "\n--$key--\n";
116      touch($old_name);
117      $res = rename($old_name, $new_name, $value);
118      var_dump($res);
119      if ($res == true) {
120         unlink($new_name);
121      }
122      else {
123         unlink($old_name);
124      }
125};
126
127fclose($fileRes);
128
129?>
130===DONE===
131--EXPECTF--
132*** Testing rename() : usage variation ***
133
134--int 0--
135Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d)
136bool(false)
137
138--int 1--
139Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d)
140bool(false)
141
142--int 12345--
143Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d)
144bool(false)
145
146--int -12345--
147Error: 2 - rename() expects parameter 3 to be resource, integer given, %s(%d)
148bool(false)
149
150--float 10.5--
151Error: 2 - rename() expects parameter 3 to be resource, float given, %s(%d)
152bool(false)
153
154--float -10.5--
155Error: 2 - rename() expects parameter 3 to be resource, float given, %s(%d)
156bool(false)
157
158--float 12.3456789000e10--
159Error: 2 - rename() expects parameter 3 to be resource, float given, %s(%d)
160bool(false)
161
162--float -12.3456789000e10--
163Error: 2 - rename() expects parameter 3 to be resource, float given, %s(%d)
164bool(false)
165
166--float .5--
167Error: 2 - rename() expects parameter 3 to be resource, float given, %s(%d)
168bool(false)
169
170--empty array--
171Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d)
172bool(false)
173
174--int indexed array--
175Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d)
176bool(false)
177
178--associative array--
179Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d)
180bool(false)
181
182--nested arrays--
183Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d)
184bool(false)
185
186--uppercase NULL--
187Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d)
188bool(false)
189
190--lowercase null--
191Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d)
192bool(false)
193
194--lowercase true--
195Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d)
196bool(false)
197
198--lowercase false--
199Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d)
200bool(false)
201
202--uppercase TRUE--
203Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d)
204bool(false)
205
206--uppercase FALSE--
207Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d)
208bool(false)
209
210--empty string DQ--
211Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
212bool(false)
213
214--empty string SQ--
215Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
216bool(false)
217
218--string DQ--
219Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
220bool(false)
221
222--string SQ--
223Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
224bool(false)
225
226--mixed case string--
227Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
228bool(false)
229
230--heredoc--
231Error: 2 - rename() expects parameter 3 to be resource, string given, %s(%d)
232bool(false)
233
234--instance of classWithToString--
235Error: 2 - rename() expects parameter 3 to be resource, object given, %s(%d)
236bool(false)
237
238--instance of classWithoutToString--
239Error: 2 - rename() expects parameter 3 to be resource, object given, %s(%d)
240bool(false)
241
242--undefined var--
243Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d)
244bool(false)
245
246--unset var--
247Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d)
248bool(false)
249
250--file resource--
251Error: 2 - rename(): supplied resource is not a valid Stream-Context resource, %s(%d)
252bool(true)
253===DONE===
254