Annotation of embedaddon/php/ext/standard/tests/dir/dir_variation1.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test dir() function : usage variations - unexpected value for 'dir' argument
1.1.1.2 ! misho 3: --SKIPIF--
! 4: <?php
! 5: if (substr(PHP_OS, 0, 3) == 'WIN') {
! 6: die('skip.. Not valid for Windows');
! 7: }
! 8: ?>
1.1 misho 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 string values to 'directory' argument of dir() and see
19: * that the function outputs proper warning messages wherever expected.
20: */
21:
22: echo "*** Testing dir() : unexpected values for \$directory argument ***\n";
23:
24: // get an unset variable
25: $unset_var = 10;
26: unset($unset_var);
27:
28: class A
29: {
30: public $var;
31: public function init() {
32: $this->var = 10;
33: }
34: }
35:
36: // get a resource variable
37: $fp = fopen(__FILE__, "r"); // get a file handle
38: $dfp = opendir( dirname(__FILE__) ); // get a dir handle
39:
40: // unexpected values to be passed to $directory argument
41: $unexpected_values = array (
42:
43: // array data
44: /*1*/ array(),
45: array(0),
46: array(1),
47: array(1, 2),
48: array('color' => 'red', 'item' => 'pen'),
49:
50: // null data
51: /*6*/ NULL,
52: null,
53:
54: // boolean data
55: /*8*/ true,
56: false,
57: TRUE,
58: FALSE,
59:
60: // empty data
61: /*12*/ "",
62: '',
63:
64: // undefined data
65: /*14*/ @$undefined_var,
66:
67: // unset data
68: /*15*/ @$unset_var,
69:
70: // resource variable(dir and file handle)
71: /*16*/ $fp,
72: $dfp,
73:
74: // object data
75: /*18*/ new A()
76: );
77:
78: // loop through various elements of $unexpected_values to check the behavior of dir()
79: $iterator = 1;
80: foreach( $unexpected_values as $unexpected_value ) {
81: echo "\n-- Iteration $iterator --\n";
82: var_dump( dir($unexpected_value) );
83: $iterator++;
84: }
85:
86: fclose($fp);
87: closedir($dfp);
88: echo "Done";
89: ?>
90: --EXPECTF--
91: *** Testing dir() : unexpected values for $directory argument ***
92:
93: -- Iteration 1 --
94:
95: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
96: NULL
97:
98: -- Iteration 2 --
99:
100: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
101: NULL
102:
103: -- Iteration 3 --
104:
105: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
106: NULL
107:
108: -- Iteration 4 --
109:
110: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
111: NULL
112:
113: -- Iteration 5 --
114:
115: Warning: dir() expects parameter 1 to be string, array given in %s on line %d
116: NULL
117:
118: -- Iteration 6 --
119: bool(false)
120:
121: -- Iteration 7 --
122: bool(false)
123:
124: -- Iteration 8 --
125:
126: Warning: dir(1): failed to open dir: %s in %s on line %d
127: bool(false)
128:
129: -- Iteration 9 --
130: bool(false)
131:
132: -- Iteration 10 --
133:
134: Warning: dir(1): failed to open dir: %s in %s on line %d
135: bool(false)
136:
137: -- Iteration 11 --
138: bool(false)
139:
140: -- Iteration 12 --
141: bool(false)
142:
143: -- Iteration 13 --
144: bool(false)
145:
146: -- Iteration 14 --
147: bool(false)
148:
149: -- Iteration 15 --
150: bool(false)
151:
152: -- Iteration 16 --
153:
154: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d
155: NULL
156:
157: -- Iteration 17 --
158:
159: Warning: dir() expects parameter 1 to be string, resource given in %s on line %d
160: NULL
161:
162: -- Iteration 18 --
163:
164: Warning: dir() expects parameter 1 to be string, object given in %s on line %d
165: NULL
166: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>