1--TEST--
2Test dir() function : usage variations - unexpected value for 'context' argument
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) != 'WIN') {
6  die("skip Valid only on Windows");
7}
8?>
9--FILE--
10<?php
11/*
12 * Prototype  : object dir(string $directory[, resource $context])
13 * Description: Directory class with properties, handle and class and methods read, rewind and close
14 * Source code: ext/standard/dir.c
15 */
16
17/*
18 * Passing non resource values to 'context' argument of dir() and see
19 * that the function outputs proper warning messages wherever expected.
20 */
21
22echo "*** Testing dir() : unexpected values for \$context argument ***\n";
23
24// create the temporary directory
25$file_path = dirname(__FILE__);
26$directory = $file_path."/私はガラスを食べられますdir_variation2";
27@mkdir($directory);
28
29// get an unset variable
30$unset_var = stream_context_create();
31unset($unset_var);
32
33class classA
34{
35  public $var;
36  public function init() {
37    $this->var = 10;
38  }
39}
40
41// heredoc string
42$heredoc = <<<EOT
43hello world
44EOT;
45
46// unexpected values to be passed to $directory argument
47$unexpected_values = array (
48       // int data
49/*1*/  0,
50       1,
51       12345,
52       -2345,
53
54       // float data
55/*5*/  10.5,
56       -10.5,
57       12.3456789000e10,
58       12.3456789000E-10,
59       .5,
60
61       // array data
62/*10*/ array(),
63       array(0),
64       array(1),
65       array(1, 2),
66       array('color' => 'red', 'item' => 'pen'),
67
68
69       // null data
70/*15*/ NULL,
71       null,
72
73       // boolean data
74/*17*/ true,
75       false,
76       TRUE,
77       FALSE,
78
79       // empty data
80/*21*/ "",
81       '',
82
83       // string data
84/*23*/ "string",
85       'string',
86       $heredoc,
87
88       // object data
89/*26*/ new classA(),
90
91       // undefined data
92/*27*/ @$undefined_var,
93
94       // unset data
95/*28*/ @$unset_var
96);
97
98// loop through various elements of $unexpected_values to check the behavior of dir()
99$iterator = 1;
100foreach( $unexpected_values as $unexpected_value ) {
101  echo "\n-- Iteration $iterator --";
102  var_dump( dir($directory, $unexpected_value) );
103  $iterator++;
104}
105
106echo "Done";
107?>
108--CLEAN--
109<?php
110$file_path = dirname(__FILE__);
111$directory = $file_path."/私はガラスを食べられますdir_variation2";
112
113rmdir($directory);
114?>
115--EXPECTF--
116*** Testing dir() : unexpected values for $context argument ***
117
118-- Iteration 1 --
119Warning: dir() expects parameter 2 to be resource, int given in %s on line %d
120NULL
121
122-- Iteration 2 --
123Warning: dir() expects parameter 2 to be resource, int given in %s on line %d
124NULL
125
126-- Iteration 3 --
127Warning: dir() expects parameter 2 to be resource, int given in %s on line %d
128NULL
129
130-- Iteration 4 --
131Warning: dir() expects parameter 2 to be resource, int given in %s on line %d
132NULL
133
134-- Iteration 5 --
135Warning: dir() expects parameter 2 to be resource, float given in %s on line %d
136NULL
137
138-- Iteration 6 --
139Warning: dir() expects parameter 2 to be resource, float given in %s on line %d
140NULL
141
142-- Iteration 7 --
143Warning: dir() expects parameter 2 to be resource, float given in %s on line %d
144NULL
145
146-- Iteration 8 --
147Warning: dir() expects parameter 2 to be resource, float given in %s on line %d
148NULL
149
150-- Iteration 9 --
151Warning: dir() expects parameter 2 to be resource, float given in %s on line %d
152NULL
153
154-- Iteration 10 --
155Warning: dir() expects parameter 2 to be resource, array given in %s on line %d
156NULL
157
158-- Iteration 11 --
159Warning: dir() expects parameter 2 to be resource, array given in %s on line %d
160NULL
161
162-- Iteration 12 --
163Warning: dir() expects parameter 2 to be resource, array given in %s on line %d
164NULL
165
166-- Iteration 13 --
167Warning: dir() expects parameter 2 to be resource, array given in %s on line %d
168NULL
169
170-- Iteration 14 --
171Warning: dir() expects parameter 2 to be resource, array given in %s on line %d
172NULL
173
174-- Iteration 15 --
175Warning: dir() expects parameter 2 to be resource, null given in %s on line %d
176NULL
177
178-- Iteration 16 --
179Warning: dir() expects parameter 2 to be resource, null given in %s on line %d
180NULL
181
182-- Iteration 17 --
183Warning: dir() expects parameter 2 to be resource, bool given in %s on line %d
184NULL
185
186-- Iteration 18 --
187Warning: dir() expects parameter 2 to be resource, bool given in %s on line %d
188NULL
189
190-- Iteration 19 --
191Warning: dir() expects parameter 2 to be resource, bool given in %s on line %d
192NULL
193
194-- Iteration 20 --
195Warning: dir() expects parameter 2 to be resource, bool given in %s on line %d
196NULL
197
198-- Iteration 21 --
199Warning: dir() expects parameter 2 to be resource, string given in %s on line %d
200NULL
201
202-- Iteration 22 --
203Warning: dir() expects parameter 2 to be resource, string given in %s on line %d
204NULL
205
206-- Iteration 23 --
207Warning: dir() expects parameter 2 to be resource, string given in %s on line %d
208NULL
209
210-- Iteration 24 --
211Warning: dir() expects parameter 2 to be resource, string given in %s on line %d
212NULL
213
214-- Iteration 25 --
215Warning: dir() expects parameter 2 to be resource, string given in %s on line %d
216NULL
217
218-- Iteration 26 --
219Warning: dir() expects parameter 2 to be resource, object given in %s on line %d
220NULL
221
222-- Iteration 27 --
223Warning: dir() expects parameter 2 to be resource, null given in %s on line %d
224NULL
225
226-- Iteration 28 --
227Warning: dir() expects parameter 2 to be resource, null given in %s on line %d
228NULL
229Done
230