blob: 28713700d1785a40ba0d886454b430c48b0acf98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
--TEST--
Bug #55701 (GlobIterator throws LogicException with message 'The parent constructor was not called')
--FILE--
<?php
//
// Some methods of GlobIterator do not throw a RuntimeException when the glob pattern doesn't match any file.
// Most methods of GlobIterator throw a RuntimeException when the glob pattern does't match any file
// because they get the properties of the current file
function testBaseClass($f) {
// The tested iterator is in an invalid state; the behaviour of most of its methods is undefined
try {
$f();
echo "ran normally (expected)\n";
} catch (RuntimeException $e) {
// Throwing a RuntimeException is the correct behaviour for some methods
echo "ran normally (expected)\n";
} catch (LogicException $e) {
// Throwing a LogicException is not correct
echo "threw LogicException (unexpected)\n";
}
}
//
// The derived classes must throw LogicException if the parent class constructor was not called
function testChildClass($f) {
try {
$f();
echo "didn't throw (unexpected)\n";
} catch (LogicException $e) {
echo "threw LogicException (expected)\n";
} catch (Exception $e) {
echo "threw other exception (unexpected)\n";
}
}
//
// It must not throw LogicException when the iterator is not valid
echo "->count()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->count();
} );
echo "->rewind()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->rewind();
} );
echo "->getFlags()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getFlags();
} );
echo "->setFlags()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->setFlags(FilesystemIterator::KEY_AS_PATHNAME);
} );
echo "->valid()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->valid();
} );
//
// When the iterator is not valid, the behaviour of the next methods is undefined
// Some of them throw a RuntimeException while others just return an invalid value
// However, they must not throw LogicException
echo "->current()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->current();
} );
echo "->key()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->key();
} );
echo "->next()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->next();
} );
echo "->getATime()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getATime();
} );
echo "->getBasename()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getBasename();
} );
echo "->getCTime()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getCTime();
} );
echo "->getExtension()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getExtension();
} );
echo "->getFilename()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getFilename();
} );
echo "->getGroup()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getGroup();
} );
echo "->getInode()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getInode();
} );
echo "->getMTime()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getMTime();
} );
echo "->getOwner()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getOwner();
} );
echo "->getPath()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getPath();
} );
echo "->getPathname()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getPathname();
} );
echo "->getPerms()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getPerms();
} );
echo "->getSize()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getSize();
} );
echo "->getType()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->getType();
} );
echo "->isDir()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isDir();
} );
echo "->isDot()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isDot();
} );
echo "->isExecutable()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isExecutable();
} );
echo "->isFile()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isFile();
} );
echo "->isLink()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isLink();
} );
echo "->isReadable()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isReadable();
} );
echo "->isWritable()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->isWritable();
} );
echo "->seek()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->seek(0);
} );
echo "->__toString()... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.abcdefghij');
$o->__toString();
} );
//
// Supplemental test: no method should throw LogicException if it is invoked
// after a successful iteration over a non-empty list of files.
echo "non-empty GlobIterator... ";
testBaseClass( function() {
$o = new GlobIterator(__DIR__.'/*.phpt');
foreach ($o as $file) {
// nothing here, just consume all the items
}
// This must not throw an exception
$o->count();
} );
//
// The correct existing behaviour must not change
// The classes SplFileObject and SplTempFileObject are not affected by the bug
echo "======================= test there are no regressions =======================\n";
echo "SplFileObject existent file... ";
testBaseClass( function() {
$o = new SplFileObject(__FILE__);
$o->fread(1);
} );
echo "SplFileObject non-existent file... ";
testBaseClass( function() {
$o = new SplFileObject('/tmp/abcdefghij.abcdefghij');
$o->fread(1);
} );
//
// Check that when derived classes do not call GlobIterator::__construct()
// the LogicException is thrown (don't break the behaviour introduced to fix bug #54384)
echo "extends GlobIterator... ";
class GlobIteratorChild extends GlobIterator {
public function __construct() {}
}
testChildClass( function() {
$o = new GlobIteratorChild();
$o->count();
} );
echo "extends SplFileObject... ";
class SplFileObjectChild extends SplFileObject {
public function __construct() {}
}
testChildClass( function() {
$o = new SplFileObjectChild();
$o->count();
} );
echo "extends SplTempFileObject... ";
class SplTempFileObjectChild extends SplTempFileObject {
public function __construct() {}
}
testChildClass( function() {
$o = new SplTempFileObjectChild();
$o->count();
} );
--EXPECT--
->count()... ran normally (expected)
->rewind()... ran normally (expected)
->getFlags()... ran normally (expected)
->setFlags()... ran normally (expected)
->valid()... ran normally (expected)
->current()... ran normally (expected)
->key()... ran normally (expected)
->next()... ran normally (expected)
->getATime()... ran normally (expected)
->getBasename()... ran normally (expected)
->getCTime()... ran normally (expected)
->getExtension()... ran normally (expected)
->getFilename()... ran normally (expected)
->getGroup()... ran normally (expected)
->getInode()... ran normally (expected)
->getMTime()... ran normally (expected)
->getOwner()... ran normally (expected)
->getPath()... ran normally (expected)
->getPathname()... ran normally (expected)
->getPerms()... ran normally (expected)
->getSize()... ran normally (expected)
->getType()... ran normally (expected)
->isDir()... ran normally (expected)
->isDot()... ran normally (expected)
->isExecutable()... ran normally (expected)
->isFile()... ran normally (expected)
->isLink()... ran normally (expected)
->isReadable()... ran normally (expected)
->isWritable()... ran normally (expected)
->seek()... ran normally (expected)
->__toString()... ran normally (expected)
non-empty GlobIterator... ran normally (expected)
======================= test there are no regressions =======================
SplFileObject existent file... ran normally (expected)
SplFileObject non-existent file... ran normally (expected)
extends GlobIterator... threw LogicException (expected)
extends SplFileObject... threw LogicException (expected)
extends SplTempFileObject... threw LogicException (expected)
|