Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,1459 +0,0 @@
1
-<?php
2
-
3
-/*
4
- * This file is part of the Symfony package.
5
- *
6
- * (c) Fabien Potencier <fabien@symfony.com>
7
- *
8
- * For the full copyright and license information, please view the LICENSE
9
- * file that was distributed with this source code.
10
- */
11
-
12
-namespace Symfony\Component\Finder\Tests;
13
-
14
-use Symfony\Component\Finder\Finder;
15
-
16
-class FinderTest extends Iterator\RealIteratorTestCase
17
-{
18
-    public function testCreate()
19
-    {
20
-        $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
21
-    }
22
-
23
-    public function testDirectories()
24
-    {
25
-        $finder = $this->buildFinder();
26
-        $this->assertSame($finder, $finder->directories());
27
-        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto']), $finder->in(self::$tmpDir)->getIterator());
28
-
29
-        $finder = $this->buildFinder();
30
-        $finder->directories();
31
-        $finder->files();
32
-        $finder->directories();
33
-        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto']), $finder->in(self::$tmpDir)->getIterator());
34
-    }
35
-
36
-    public function testFiles()
37
-    {
38
-        $finder = $this->buildFinder();
39
-        $this->assertSame($finder, $finder->files());
40
-        $this->assertIterator($this->toAbsolute(['foo/bar.tmp',
41
-            'test.php',
42
-            'test.py',
43
-            'foo bar',
44
-            'qux/baz_100_1.py',
45
-            'qux/baz_1_2.py',
46
-            'qux_0_1.php',
47
-            'qux_1000_1.php',
48
-            'qux_1002_0.php',
49
-            'qux_10_2.php',
50
-            'qux_12_0.php',
51
-            'qux_2_0.php',
52
-        ]), $finder->in(self::$tmpDir)->getIterator());
53
-
54
-        $finder = $this->buildFinder();
55
-        $finder->files();
56
-        $finder->directories();
57
-        $finder->files();
58
-        $this->assertIterator($this->toAbsolute(['foo/bar.tmp',
59
-            'test.php',
60
-            'test.py',
61
-            'foo bar',
62
-            'qux/baz_100_1.py',
63
-            'qux/baz_1_2.py',
64
-            'qux_0_1.php',
65
-            'qux_1000_1.php',
66
-            'qux_1002_0.php',
67
-            'qux_10_2.php',
68
-            'qux_12_0.php',
69
-            'qux_2_0.php',
70
-        ]), $finder->in(self::$tmpDir)->getIterator());
71
-    }
72
-
73
-    public function testRemoveTrailingSlash()
74
-    {
75
-        $finder = $this->buildFinder();
76
-
77
-        $expected = $this->toAbsolute([
78
-            'foo/bar.tmp',
79
-            'test.php',
80
-            'test.py',
81
-            'foo bar',
82
-            'qux/baz_100_1.py',
83
-            'qux/baz_1_2.py',
84
-            'qux_0_1.php',
85
-            'qux_1000_1.php',
86
-            'qux_1002_0.php',
87
-            'qux_10_2.php',
88
-            'qux_12_0.php',
89
-            'qux_2_0.php',
90
-        ]);
91
-        $in = self::$tmpDir.'//';
92
-
93
-        $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
94
-    }
95
-
96
-    public function testSymlinksNotResolved()
97
-    {
98
-        if ('\\' === \DIRECTORY_SEPARATOR) {
99
-            $this->markTestSkipped('symlinks are not supported on Windows');
100
-        }
101
-
102
-        $finder = $this->buildFinder();
103
-
104
-        symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
105
-        $expected = $this->toAbsolute(['baz/bar.tmp']);
106
-        $in = self::$tmpDir.'/baz/';
107
-        try {
108
-            $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
109
-            unlink($this->toAbsolute('baz'));
110
-        } catch (\Exception $e) {
111
-            unlink($this->toAbsolute('baz'));
112
-            throw $e;
113
-        }
114
-    }
115
-
116
-    public function testBackPathNotNormalized()
117
-    {
118
-        $finder = $this->buildFinder();
119
-
120
-        $expected = $this->toAbsolute(['foo/../foo/bar.tmp']);
121
-        $in = self::$tmpDir.'/foo/../foo/';
122
-        $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
123
-    }
124
-
125
-    public function testDepth()
126
-    {
127
-        $finder = $this->buildFinder();
128
-        $this->assertSame($finder, $finder->depth('< 1'));
129
-        $this->assertIterator($this->toAbsolute(['foo',
130
-            'test.php',
131
-            'test.py',
132
-            'toto',
133
-            'foo bar',
134
-            'qux',
135
-            'qux_0_1.php',
136
-            'qux_1000_1.php',
137
-            'qux_1002_0.php',
138
-            'qux_10_2.php',
139
-            'qux_12_0.php',
140
-            'qux_2_0.php',
141
-        ]), $finder->in(self::$tmpDir)->getIterator());
142
-
143
-        $finder = $this->buildFinder();
144
-        $this->assertSame($finder, $finder->depth('<= 0'));
145
-        $this->assertIterator($this->toAbsolute(['foo',
146
-            'test.php',
147
-            'test.py',
148
-            'toto',
149
-            'foo bar',
150
-            'qux',
151
-            'qux_0_1.php',
152
-            'qux_1000_1.php',
153
-            'qux_1002_0.php',
154
-            'qux_10_2.php',
155
-            'qux_12_0.php',
156
-            'qux_2_0.php',
157
-        ]), $finder->in(self::$tmpDir)->getIterator());
158
-
159
-        $finder = $this->buildFinder();
160
-        $this->assertSame($finder, $finder->depth('>= 1'));
161
-        $this->assertIterator($this->toAbsolute([
162
-            'foo/bar.tmp',
163
-            'qux/baz_100_1.py',
164
-            'qux/baz_1_2.py',
165
-        ]), $finder->in(self::$tmpDir)->getIterator());
166
-
167
-        $finder = $this->buildFinder();
168
-        $finder->depth('< 1')->depth('>= 1');
169
-        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
170
-    }
171
-
172
-    public function testDepthWithArrayParam()
173
-    {
174
-        $finder = $this->buildFinder();
175
-        $finder->depth(['>= 1', '< 2']);
176
-        $this->assertIterator($this->toAbsolute([
177
-            'foo/bar.tmp',
178
-            'qux/baz_100_1.py',
179
-            'qux/baz_1_2.py',
180
-        ]), $finder->in(self::$tmpDir)->getIterator());
181
-    }
182
-
183
-    public function testName()
184
-    {
185
-        $finder = $this->buildFinder();
186
-        $this->assertSame($finder, $finder->name('*.php'));
187
-        $this->assertIterator($this->toAbsolute([
188
-            'test.php',
189
-            'qux_0_1.php',
190
-            'qux_1000_1.php',
191
-            'qux_1002_0.php',
192
-            'qux_10_2.php',
193
-            'qux_12_0.php',
194
-            'qux_2_0.php',
195
-        ]), $finder->in(self::$tmpDir)->getIterator());
196
-
197
-        $finder = $this->buildFinder();
198
-        $finder->name('test.ph*');
199
-        $finder->name('test.py');
200
-        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
201
-
202
-        $finder = $this->buildFinder();
203
-        $finder->name('~^test~i');
204
-        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
205
-
206
-        $finder = $this->buildFinder();
207
-        $finder->name('~\\.php$~i');
208
-        $this->assertIterator($this->toAbsolute([
209
-            'test.php',
210
-            'qux_0_1.php',
211
-            'qux_1000_1.php',
212
-            'qux_1002_0.php',
213
-            'qux_10_2.php',
214
-            'qux_12_0.php',
215
-            'qux_2_0.php',
216
-        ]), $finder->in(self::$tmpDir)->getIterator());
217
-
218
-        $finder = $this->buildFinder();
219
-        $finder->name('test.p{hp,y}');
220
-        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
221
-    }
222
-
223
-    public function testNameWithArrayParam()
224
-    {
225
-        $finder = $this->buildFinder();
226
-        $finder->name(['test.php', 'test.py']);
227
-        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
228
-    }
229
-
230
-    public function testNotName()
231
-    {
232
-        $finder = $this->buildFinder();
233
-        $this->assertSame($finder, $finder->notName('*.php'));
234
-        $this->assertIterator($this->toAbsolute([
235
-            'foo',
236
-            'foo/bar.tmp',
237
-            'test.py',
238
-            'toto',
239
-            'foo bar',
240
-            'qux',
241
-            'qux/baz_100_1.py',
242
-            'qux/baz_1_2.py',
243
-        ]), $finder->in(self::$tmpDir)->getIterator());
244
-
245
-        $finder = $this->buildFinder();
246
-        $finder->notName('*.php');
247
-        $finder->notName('*.py');
248
-        $this->assertIterator($this->toAbsolute([
249
-            'foo',
250
-            'foo/bar.tmp',
251
-            'toto',
252
-            'foo bar',
253
-            'qux',
254
-        ]), $finder->in(self::$tmpDir)->getIterator());
255
-
256
-        $finder = $this->buildFinder();
257
-        $finder->name('test.ph*');
258
-        $finder->name('test.py');
259
-        $finder->notName('*.php');
260
-        $finder->notName('*.py');
261
-        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
262
-
263
-        $finder = $this->buildFinder();
264
-        $finder->name('test.ph*');
265
-        $finder->name('test.py');
266
-        $finder->notName('*.p{hp,y}');
267
-        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
268
-    }
269
-
270
-    public function testNotNameWithArrayParam()
271
-    {
272
-        $finder = $this->buildFinder();
273
-        $finder->notName(['*.php', '*.py']);
274
-        $this->assertIterator($this->toAbsolute([
275
-            'foo',
276
-            'foo/bar.tmp',
277
-            'toto',
278
-            'foo bar',
279
-            'qux',
280
-        ]), $finder->in(self::$tmpDir)->getIterator());
281
-    }
282
-
283
-    /**
284
-     * @dataProvider getRegexNameTestData
285
-     */
286
-    public function testRegexName($regex)
287
-    {
288
-        $finder = $this->buildFinder();
289
-        $finder->name($regex);
290
-        $this->assertIterator($this->toAbsolute([
291
-            'test.py',
292
-            'test.php',
293
-        ]), $finder->in(self::$tmpDir)->getIterator());
294
-    }
295
-
296
-    public function testSize()
297
-    {
298
-        $finder = $this->buildFinder();
299
-        $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
300
-        $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
301
-    }
302
-
303
-    public function testSizeWithArrayParam()
304
-    {
305
-        $finder = $this->buildFinder();
306
-        $this->assertSame($finder, $finder->files()->size(['< 1K', '> 500']));
307
-        $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
308
-    }
309
-
310
-    public function testDate()
311
-    {
312
-        $finder = $this->buildFinder();
313
-        $this->assertSame($finder, $finder->files()->date('until last month'));
314
-        $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
315
-    }
316
-
317
-    public function testDateWithArrayParam()
318
-    {
319
-        $finder = $this->buildFinder();
320
-        $this->assertSame($finder, $finder->files()->date(['>= 2005-10-15', 'until last month']));
321
-        $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
322
-    }
323
-
324
-    public function testExclude()
325
-    {
326
-        $finder = $this->buildFinder();
327
-        $this->assertSame($finder, $finder->exclude('foo'));
328
-        $this->assertIterator($this->toAbsolute([
329
-            'test.php',
330
-            'test.py',
331
-            'toto',
332
-            'foo bar',
333
-            'qux',
334
-            'qux/baz_100_1.py',
335
-            'qux/baz_1_2.py',
336
-            'qux_0_1.php',
337
-            'qux_1000_1.php',
338
-            'qux_1002_0.php',
339
-            'qux_10_2.php',
340
-            'qux_12_0.php',
341
-            'qux_2_0.php',
342
-        ]), $finder->in(self::$tmpDir)->getIterator());
343
-    }
344
-
345
-    public function testIgnoreVCS()
346
-    {
347
-        $finder = $this->buildFinder();
348
-        $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
349
-        $this->assertIterator($this->toAbsolute([
350
-            '.gitignore',
351
-            '.git',
352
-            'foo',
353
-            'foo/bar.tmp',
354
-            'test.php',
355
-            'test.py',
356
-            'toto',
357
-            'toto/.git',
358
-            '.bar',
359
-            '.foo',
360
-            '.foo/.bar',
361
-            '.foo/bar',
362
-            'foo bar',
363
-            'qux',
364
-            'qux/baz_100_1.py',
365
-            'qux/baz_1_2.py',
366
-            'qux_0_1.php',
367
-            'qux_1000_1.php',
368
-            'qux_1002_0.php',
369
-            'qux_10_2.php',
370
-            'qux_12_0.php',
371
-            'qux_2_0.php',
372
-        ]), $finder->in(self::$tmpDir)->getIterator());
373
-
374
-        $finder = $this->buildFinder();
375
-        $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
376
-        $this->assertIterator($this->toAbsolute([
377
-            '.gitignore',
378
-            '.git',
379
-            'foo',
380
-            'foo/bar.tmp',
381
-            'test.php',
382
-            'test.py',
383
-            'toto',
384
-            'toto/.git',
385
-            '.bar',
386
-            '.foo',
387
-            '.foo/.bar',
388
-            '.foo/bar',
389
-            'foo bar',
390
-            'qux',
391
-            'qux/baz_100_1.py',
392
-            'qux/baz_1_2.py',
393
-            'qux_0_1.php',
394
-            'qux_1000_1.php',
395
-            'qux_1002_0.php',
396
-            'qux_10_2.php',
397
-            'qux_12_0.php',
398
-            'qux_2_0.php',
399
-        ]), $finder->in(self::$tmpDir)->getIterator());
400
-
401
-        $finder = $this->buildFinder();
402
-        $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
403
-        $this->assertIterator($this->toAbsolute([
404
-            '.gitignore',
405
-            'foo',
406
-            'foo/bar.tmp',
407
-            'test.php',
408
-            'test.py',
409
-            'toto',
410
-            '.bar',
411
-            '.foo',
412
-            '.foo/.bar',
413
-            '.foo/bar',
414
-            'foo bar',
415
-            'qux',
416
-            'qux/baz_100_1.py',
417
-            'qux/baz_1_2.py',
418
-            'qux_0_1.php',
419
-            'qux_1000_1.php',
420
-            'qux_1002_0.php',
421
-            'qux_10_2.php',
422
-            'qux_12_0.php',
423
-            'qux_2_0.php',
424
-        ]), $finder->in(self::$tmpDir)->getIterator());
425
-    }
426
-
427
-    public function testIgnoreVCSIgnored()
428
-    {
429
-        $finder = $this->buildFinder();
430
-        $this->assertSame(
431
-            $finder,
432
-            $finder
433
-                ->ignoreVCS(true)
434
-                ->ignoreDotFiles(true)
435
-                ->ignoreVCSIgnored(true)
436
-        );
437
-        $this->assertIterator($this->toAbsolute([
438
-            'foo',
439
-            'foo/bar.tmp',
440
-            'test.py',
441
-            'toto',
442
-            'foo bar',
443
-            'qux',
444
-            'qux/baz_100_1.py',
445
-            'qux/baz_1_2.py',
446
-        ]), $finder->in(self::$tmpDir)->getIterator());
447
-    }
448
-
449
-    public function testIgnoreVCSCanBeDisabledAfterFirstIteration()
450
-    {
451
-        $finder = $this->buildFinder();
452
-        $finder->in(self::$tmpDir);
453
-        $finder->ignoreDotFiles(false);
454
-
455
-        $this->assertIterator($this->toAbsolute([
456
-            '.gitignore',
457
-            'foo',
458
-            'foo/bar.tmp',
459
-            'qux',
460
-            'qux/baz_100_1.py',
461
-            'qux/baz_1_2.py',
462
-            'qux_0_1.php',
463
-            'qux_1000_1.php',
464
-            'qux_1002_0.php',
465
-            'qux_10_2.php',
466
-            'qux_12_0.php',
467
-            'qux_2_0.php',
468
-            'test.php',
469
-            'test.py',
470
-            'toto',
471
-            '.bar',
472
-            '.foo',
473
-            '.foo/.bar',
474
-            '.foo/bar',
475
-            'foo bar',
476
-        ]), $finder->getIterator());
477
-
478
-        $finder->ignoreVCS(false);
479
-        $this->assertIterator($this->toAbsolute([
480
-            '.gitignore',
481
-            '.git',
482
-            'foo',
483
-            'foo/bar.tmp',
484
-            'qux',
485
-            'qux/baz_100_1.py',
486
-            'qux/baz_1_2.py',
487
-            'qux_0_1.php',
488
-            'qux_1000_1.php',
489
-            'qux_1002_0.php',
490
-            'qux_10_2.php',
491
-            'qux_12_0.php',
492
-            'qux_2_0.php',
493
-            'test.php',
494
-            'test.py',
495
-            'toto',
496
-            'toto/.git',
497
-            '.bar',
498
-            '.foo',
499
-            '.foo/.bar',
500
-            '.foo/bar',
501
-            'foo bar',
502
-        ]), $finder->getIterator());
503
-    }
504
-
505
-    public function testIgnoreDotFiles()
506
-    {
507
-        $finder = $this->buildFinder();
508
-        $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
509
-        $this->assertIterator($this->toAbsolute([
510
-            '.gitignore',
511
-            '.git',
512
-            '.bar',
513
-            '.foo',
514
-            '.foo/.bar',
515
-            '.foo/bar',
516
-            'foo',
517
-            'foo/bar.tmp',
518
-            'test.php',
519
-            'test.py',
520
-            'toto',
521
-            'toto/.git',
522
-            'foo bar',
523
-            'qux',
524
-            'qux/baz_100_1.py',
525
-            'qux/baz_1_2.py',
526
-            'qux_0_1.php',
527
-            'qux_1000_1.php',
528
-            'qux_1002_0.php',
529
-            'qux_10_2.php',
530
-            'qux_12_0.php',
531
-            'qux_2_0.php',
532
-        ]), $finder->in(self::$tmpDir)->getIterator());
533
-
534
-        $finder = $this->buildFinder();
535
-        $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
536
-        $this->assertIterator($this->toAbsolute([
537
-            '.gitignore',
538
-            '.git',
539
-            '.bar',
540
-            '.foo',
541
-            '.foo/.bar',
542
-            '.foo/bar',
543
-            'foo',
544
-            'foo/bar.tmp',
545
-            'test.php',
546
-            'test.py',
547
-            'toto',
548
-            'toto/.git',
549
-            'foo bar',
550
-            'qux',
551
-            'qux/baz_100_1.py',
552
-            'qux/baz_1_2.py',
553
-            'qux_0_1.php',
554
-            'qux_1000_1.php',
555
-            'qux_1002_0.php',
556
-            'qux_10_2.php',
557
-            'qux_12_0.php',
558
-            'qux_2_0.php',
559
-        ]), $finder->in(self::$tmpDir)->getIterator());
560
-
561
-        $finder = $this->buildFinder();
562
-        $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
563
-        $this->assertIterator($this->toAbsolute([
564
-            'foo',
565
-            'foo/bar.tmp',
566
-            'test.php',
567
-            'test.py',
568
-            'toto',
569
-            'foo bar',
570
-            'qux',
571
-            'qux/baz_100_1.py',
572
-            'qux/baz_1_2.py',
573
-            'qux_0_1.php',
574
-            'qux_1000_1.php',
575
-            'qux_1002_0.php',
576
-            'qux_10_2.php',
577
-            'qux_12_0.php',
578
-            'qux_2_0.php',
579
-        ]), $finder->in(self::$tmpDir)->getIterator());
580
-    }
581
-
582
-    public function testIgnoreDotFilesCanBeDisabledAfterFirstIteration()
583
-    {
584
-        $finder = $this->buildFinder();
585
-        $finder->in(self::$tmpDir);
586
-
587
-        $this->assertIterator($this->toAbsolute([
588
-            'foo',
589
-            'foo/bar.tmp',
590
-            'qux',
591
-            'qux/baz_100_1.py',
592
-            'qux/baz_1_2.py',
593
-            'qux_0_1.php',
594
-            'qux_1000_1.php',
595
-            'qux_1002_0.php',
596
-            'qux_10_2.php',
597
-            'qux_12_0.php',
598
-            'qux_2_0.php',
599
-            'test.php',
600
-            'test.py',
601
-            'toto',
602
-            'foo bar',
603
-        ]), $finder->getIterator());
604
-
605
-        $finder->ignoreDotFiles(false);
606
-        $this->assertIterator($this->toAbsolute([
607
-            '.gitignore',
608
-            'foo',
609
-            'foo/bar.tmp',
610
-            'qux',
611
-            'qux/baz_100_1.py',
612
-            'qux/baz_1_2.py',
613
-            'qux_0_1.php',
614
-            'qux_1000_1.php',
615
-            'qux_1002_0.php',
616
-            'qux_10_2.php',
617
-            'qux_12_0.php',
618
-            'qux_2_0.php',
619
-            'test.php',
620
-            'test.py',
621
-            'toto',
622
-            '.bar',
623
-            '.foo',
624
-            '.foo/.bar',
625
-            '.foo/bar',
626
-            'foo bar',
627
-        ]), $finder->getIterator());
628
-    }
629
-
630
-    public function testSortByName()
631
-    {
632
-        $finder = $this->buildFinder();
633
-        $this->assertSame($finder, $finder->sortByName());
634
-        $this->assertIterator($this->toAbsolute([
635
-            'foo',
636
-            'foo bar',
637
-            'foo/bar.tmp',
638
-            'qux',
639
-            'qux/baz_100_1.py',
640
-            'qux/baz_1_2.py',
641
-            'qux_0_1.php',
642
-            'qux_1000_1.php',
643
-            'qux_1002_0.php',
644
-            'qux_10_2.php',
645
-            'qux_12_0.php',
646
-            'qux_2_0.php',
647
-            'test.php',
648
-            'test.py',
649
-            'toto',
650
-        ]), $finder->in(self::$tmpDir)->getIterator());
651
-    }
652
-
653
-    public function testSortByType()
654
-    {
655
-        $finder = $this->buildFinder();
656
-        $this->assertSame($finder, $finder->sortByType());
657
-        $this->assertIterator($this->toAbsolute([
658
-            'foo',
659
-            'foo bar',
660
-            'toto',
661
-            'foo/bar.tmp',
662
-            'test.php',
663
-            'test.py',
664
-            'qux',
665
-            'qux/baz_100_1.py',
666
-            'qux/baz_1_2.py',
667
-            'qux_0_1.php',
668
-            'qux_1000_1.php',
669
-            'qux_1002_0.php',
670
-            'qux_10_2.php',
671
-            'qux_12_0.php',
672
-            'qux_2_0.php',
673
-        ]), $finder->in(self::$tmpDir)->getIterator());
674
-    }
675
-
676
-    public function testSortByAccessedTime()
677
-    {
678
-        $finder = $this->buildFinder();
679
-        $this->assertSame($finder, $finder->sortByAccessedTime());
680
-        $this->assertIterator($this->toAbsolute([
681
-            'foo/bar.tmp',
682
-            'test.php',
683
-            'toto',
684
-            'test.py',
685
-            'foo',
686
-            'foo bar',
687
-            'qux',
688
-            'qux/baz_100_1.py',
689
-            'qux/baz_1_2.py',
690
-            'qux_0_1.php',
691
-            'qux_1000_1.php',
692
-            'qux_1002_0.php',
693
-            'qux_10_2.php',
694
-            'qux_12_0.php',
695
-            'qux_2_0.php',
696
-        ]), $finder->in(self::$tmpDir)->getIterator());
697
-    }
698
-
699
-    public function testSortByChangedTime()
700
-    {
701
-        $finder = $this->buildFinder();
702
-        $this->assertSame($finder, $finder->sortByChangedTime());
703
-        $this->assertIterator($this->toAbsolute([
704
-            'toto',
705
-            'test.py',
706
-            'test.php',
707
-            'foo/bar.tmp',
708
-            'foo',
709
-            'foo bar',
710
-            'qux',
711
-            'qux/baz_100_1.py',
712
-            'qux/baz_1_2.py',
713
-            'qux_0_1.php',
714
-            'qux_1000_1.php',
715
-            'qux_1002_0.php',
716
-            'qux_10_2.php',
717
-            'qux_12_0.php',
718
-            'qux_2_0.php',
719
-        ]), $finder->in(self::$tmpDir)->getIterator());
720
-    }
721
-
722
-    public function testSortByModifiedTime()
723
-    {
724
-        $finder = $this->buildFinder();
725
-        $this->assertSame($finder, $finder->sortByModifiedTime());
726
-        $this->assertIterator($this->toAbsolute([
727
-            'foo/bar.tmp',
728
-            'test.php',
729
-            'toto',
730
-            'test.py',
731
-            'foo',
732
-            'foo bar',
733
-            'qux',
734
-            'qux/baz_100_1.py',
735
-            'qux/baz_1_2.py',
736
-            'qux_0_1.php',
737
-            'qux_1000_1.php',
738
-            'qux_1002_0.php',
739
-            'qux_10_2.php',
740
-            'qux_12_0.php',
741
-            'qux_2_0.php',
742
-        ]), $finder->in(self::$tmpDir)->getIterator());
743
-    }
744
-
745
-    public function testReverseSorting()
746
-    {
747
-        $finder = $this->buildFinder();
748
-        $this->assertSame($finder, $finder->sortByName());
749
-        $this->assertSame($finder, $finder->reverseSorting());
750
-        $this->assertOrderedIteratorInForeach($this->toAbsolute([
751
-            'toto',
752
-            'test.py',
753
-            'test.php',
754
-            'qux_2_0.php',
755
-            'qux_12_0.php',
756
-            'qux_10_2.php',
757
-            'qux_1002_0.php',
758
-            'qux_1000_1.php',
759
-            'qux_0_1.php',
760
-            'qux/baz_1_2.py',
761
-            'qux/baz_100_1.py',
762
-            'qux',
763
-            'foo/bar.tmp',
764
-            'foo bar',
765
-            'foo',
766
-        ]), $finder->in(self::$tmpDir)->getIterator());
767
-    }
768
-
769
-    public function testSortByNameNatural()
770
-    {
771
-        $finder = $this->buildFinder();
772
-        $this->assertSame($finder, $finder->sortByName(true));
773
-        $this->assertIterator($this->toAbsolute([
774
-            'foo',
775
-            'foo bar',
776
-            'foo/bar.tmp',
777
-            'qux',
778
-            'qux/baz_100_1.py',
779
-            'qux/baz_1_2.py',
780
-            'qux_0_1.php',
781
-            'qux_1000_1.php',
782
-            'qux_1002_0.php',
783
-            'qux_10_2.php',
784
-            'qux_12_0.php',
785
-            'qux_2_0.php',
786
-            'test.php',
787
-            'test.py',
788
-            'toto',
789
-        ]), $finder->in(self::$tmpDir)->getIterator());
790
-
791
-        $finder = $this->buildFinder();
792
-        $this->assertSame($finder, $finder->sortByName(false));
793
-        $this->assertIterator($this->toAbsolute([
794
-            'foo',
795
-            'foo bar',
796
-            'foo/bar.tmp',
797
-            'qux',
798
-            'qux/baz_100_1.py',
799
-            'qux/baz_1_2.py',
800
-            'qux_0_1.php',
801
-            'qux_1000_1.php',
802
-            'qux_1002_0.php',
803
-            'qux_10_2.php',
804
-            'qux_12_0.php',
805
-            'qux_2_0.php',
806
-            'test.php',
807
-            'test.py',
808
-            'toto',
809
-        ]), $finder->in(self::$tmpDir)->getIterator());
810
-    }
811
-
812
-    public function testSort()
813
-    {
814
-        $finder = $this->buildFinder();
815
-        $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
816
-        $this->assertIterator($this->toAbsolute([
817
-            'foo',
818
-            'foo bar',
819
-            'foo/bar.tmp',
820
-            'test.php',
821
-            'test.py',
822
-            'toto',
823
-            'qux',
824
-            'qux/baz_100_1.py',
825
-            'qux/baz_1_2.py',
826
-            'qux_0_1.php',
827
-            'qux_1000_1.php',
828
-            'qux_1002_0.php',
829
-            'qux_10_2.php',
830
-            'qux_12_0.php',
831
-            'qux_2_0.php',
832
-        ]), $finder->in(self::$tmpDir)->getIterator());
833
-    }
834
-
835
-    public function testFilter()
836
-    {
837
-        $finder = $this->buildFinder();
838
-        $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
839
-        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
840
-    }
841
-
842
-    public function testFollowLinks()
843
-    {
844
-        if ('\\' == \DIRECTORY_SEPARATOR) {
845
-            $this->markTestSkipped('symlinks are not supported on Windows');
846
-        }
847
-
848
-        $finder = $this->buildFinder();
849
-        $this->assertSame($finder, $finder->followLinks());
850
-        $this->assertIterator($this->toAbsolute([
851
-            'foo',
852
-            'foo/bar.tmp',
853
-            'test.php',
854
-            'test.py',
855
-            'toto',
856
-            'foo bar',
857
-            'qux',
858
-            'qux/baz_100_1.py',
859
-            'qux/baz_1_2.py',
860
-            'qux_0_1.php',
861
-            'qux_1000_1.php',
862
-            'qux_1002_0.php',
863
-            'qux_10_2.php',
864
-            'qux_12_0.php',
865
-            'qux_2_0.php',
866
-        ]), $finder->in(self::$tmpDir)->getIterator());
867
-    }
868
-
869
-    public function testIn()
870
-    {
871
-        $finder = $this->buildFinder();
872
-        $iterator = $finder->files()->name('*.php')->depth('< 1')->in([self::$tmpDir, __DIR__])->getIterator();
873
-
874
-        $expected = [
875
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
876
-            __DIR__.\DIRECTORY_SEPARATOR.'GitignoreTest.php',
877
-            __DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
878
-            __DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
879
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_0_1.php',
880
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php',
881
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php',
882
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_10_2.php',
883
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_12_0.php',
884
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_2_0.php',
885
-        ];
886
-
887
-        $this->assertIterator($expected, $iterator);
888
-    }
889
-
890
-    /**
891
-     * @expectedException \Symfony\Component\Finder\Exception\DirectoryNotFoundException
892
-     */
893
-    public function testInWithNonExistentDirectory()
894
-    {
895
-        $finder = new Finder();
896
-        $finder->in('foobar');
897
-    }
898
-
899
-    /**
900
-     * @expectedException \InvalidArgumentException
901
-     */
902
-    public function testInWithNonExistentDirectoryLegacyException()
903
-    {
904
-        $finder = new Finder();
905
-        $finder->in('foobar');
906
-    }
907
-
908
-    public function testInWithGlob()
909
-    {
910
-        $finder = $this->buildFinder();
911
-        $finder->in([__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'])->getIterator();
912
-
913
-        $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
914
-    }
915
-
916
-    /**
917
-     * @expectedException \InvalidArgumentException
918
-     */
919
-    public function testInWithNonDirectoryGlob()
920
-    {
921
-        $finder = new Finder();
922
-        $finder->in(__DIR__.'/Fixtures/A/a*');
923
-    }
924
-
925
-    public function testInWithGlobBrace()
926
-    {
927
-        if (!\defined('GLOB_BRACE')) {
928
-            $this->markTestSkipped('Glob brace is not supported on this system.');
929
-        }
930
-
931
-        $finder = $this->buildFinder();
932
-        $finder->in([__DIR__.'/Fixtures/{A,copy/A}/B/C'])->getIterator();
933
-
934
-        $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
935
-    }
936
-
937
-    /**
938
-     * @expectedException \LogicException
939
-     */
940
-    public function testGetIteratorWithoutIn()
941
-    {
942
-        $finder = Finder::create();
943
-        $finder->getIterator();
944
-    }
945
-
946
-    public function testGetIterator()
947
-    {
948
-        $finder = $this->buildFinder();
949
-        $dirs = [];
950
-        foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
951
-            $dirs[] = (string) $dir;
952
-        }
953
-
954
-        $expected = $this->toAbsolute(['foo', 'qux', 'toto']);
955
-
956
-        sort($dirs);
957
-        sort($expected);
958
-
959
-        $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
960
-
961
-        $finder = $this->buildFinder();
962
-        $this->assertEquals(3, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
963
-
964
-        $finder = $this->buildFinder();
965
-        $a = iterator_to_array($finder->directories()->in(self::$tmpDir));
966
-        $a = array_values(array_map('strval', $a));
967
-        sort($a);
968
-        $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
969
-    }
970
-
971
-    public function testRelativePath()
972
-    {
973
-        $finder = $this->buildFinder()->in(self::$tmpDir);
974
-
975
-        $paths = [];
976
-
977
-        foreach ($finder as $file) {
978
-            $paths[] = $file->getRelativePath();
979
-        }
980
-
981
-        $ref = ['', '', '', '', '', '', '', '', '', '', '', 'foo', 'qux', 'qux', ''];
982
-
983
-        sort($ref);
984
-        sort($paths);
985
-
986
-        $this->assertEquals($ref, $paths);
987
-    }
988
-
989
-    public function testRelativePathname()
990
-    {
991
-        $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
992
-
993
-        $paths = [];
994
-
995
-        foreach ($finder as $file) {
996
-            $paths[] = $file->getRelativePathname();
997
-        }
998
-
999
-        $ref = [
1000
-            'test.php',
1001
-            'toto',
1002
-            'test.py',
1003
-            'foo',
1004
-            'foo'.\DIRECTORY_SEPARATOR.'bar.tmp',
1005
-            'foo bar',
1006
-            'qux',
1007
-            'qux'.\DIRECTORY_SEPARATOR.'baz_100_1.py',
1008
-            'qux'.\DIRECTORY_SEPARATOR.'baz_1_2.py',
1009
-            'qux_0_1.php',
1010
-            'qux_1000_1.php',
1011
-            'qux_1002_0.php',
1012
-            'qux_10_2.php',
1013
-            'qux_12_0.php',
1014
-            'qux_2_0.php',
1015
-        ];
1016
-
1017
-        sort($paths);
1018
-        sort($ref);
1019
-
1020
-        $this->assertEquals($ref, $paths);
1021
-    }
1022
-
1023
-    public function testGetFilenameWithoutExtension()
1024
-    {
1025
-        $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
1026
-
1027
-        $fileNames = [];
1028
-
1029
-        foreach ($finder as $file) {
1030
-            $fileNames[] = $file->getFilenameWithoutExtension();
1031
-        }
1032
-
1033
-        $ref = [
1034
-            'test',
1035
-            'toto',
1036
-            'test',
1037
-            'foo',
1038
-            'bar',
1039
-            'foo bar',
1040
-            'qux',
1041
-            'baz_100_1',
1042
-            'baz_1_2',
1043
-            'qux_0_1',
1044
-            'qux_1000_1',
1045
-            'qux_1002_0',
1046
-            'qux_10_2',
1047
-            'qux_12_0',
1048
-            'qux_2_0',
1049
-        ];
1050
-
1051
-        sort($fileNames);
1052
-        sort($ref);
1053
-
1054
-        $this->assertEquals($ref, $fileNames);
1055
-    }
1056
-
1057
-    public function testAppendWithAFinder()
1058
-    {
1059
-        $finder = $this->buildFinder();
1060
-        $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1061
-
1062
-        $finder1 = $this->buildFinder();
1063
-        $finder1->directories()->in(self::$tmpDir);
1064
-
1065
-        $finder = $finder->append($finder1);
1066
-
1067
-        $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'qux', 'toto']), $finder->getIterator());
1068
-    }
1069
-
1070
-    public function testAppendWithAnArray()
1071
-    {
1072
-        $finder = $this->buildFinder();
1073
-        $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1074
-
1075
-        $finder->append($this->toAbsolute(['foo', 'toto']));
1076
-
1077
-        $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
1078
-    }
1079
-
1080
-    public function testAppendReturnsAFinder()
1081
-    {
1082
-        $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append([]));
1083
-    }
1084
-
1085
-    public function testAppendDoesNotRequireIn()
1086
-    {
1087
-        $finder = $this->buildFinder();
1088
-        $finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1089
-
1090
-        $finder1 = Finder::create()->append($finder);
1091
-
1092
-        $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
1093
-    }
1094
-
1095
-    public function testCountDirectories()
1096
-    {
1097
-        $directory = Finder::create()->directories()->in(self::$tmpDir);
1098
-        $i = 0;
1099
-
1100
-        foreach ($directory as $dir) {
1101
-            ++$i;
1102
-        }
1103
-
1104
-        $this->assertCount($i, $directory);
1105
-    }
1106
-
1107
-    public function testCountFiles()
1108
-    {
1109
-        $files = Finder::create()->files()->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
1110
-        $i = 0;
1111
-
1112
-        foreach ($files as $file) {
1113
-            ++$i;
1114
-        }
1115
-
1116
-        $this->assertCount($i, $files);
1117
-    }
1118
-
1119
-    /**
1120
-     * @expectedException \LogicException
1121
-     */
1122
-    public function testCountWithoutIn()
1123
-    {
1124
-        $finder = Finder::create()->files();
1125
-        \count($finder);
1126
-    }
1127
-
1128
-    public function testHasResults()
1129
-    {
1130
-        $finder = $this->buildFinder();
1131
-        $finder->in(__DIR__);
1132
-        $this->assertTrue($finder->hasResults());
1133
-    }
1134
-
1135
-    public function testNoResults()
1136
-    {
1137
-        $finder = $this->buildFinder();
1138
-        $finder->in(__DIR__)->name('DoesNotExist');
1139
-        $this->assertFalse($finder->hasResults());
1140
-    }
1141
-
1142
-    /**
1143
-     * @dataProvider getContainsTestData
1144
-     */
1145
-    public function testContains($matchPatterns, $noMatchPatterns, $expected)
1146
-    {
1147
-        $finder = $this->buildFinder();
1148
-        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
1149
-            ->name('*.txt')->sortByName()
1150
-            ->contains($matchPatterns)
1151
-            ->notContains($noMatchPatterns);
1152
-
1153
-        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1154
-    }
1155
-
1156
-    public function testContainsOnDirectory()
1157
-    {
1158
-        $finder = $this->buildFinder();
1159
-        $finder->in(__DIR__)
1160
-            ->directories()
1161
-            ->name('Fixtures')
1162
-            ->contains('abc');
1163
-        $this->assertIterator([], $finder);
1164
-    }
1165
-
1166
-    public function testNotContainsOnDirectory()
1167
-    {
1168
-        $finder = $this->buildFinder();
1169
-        $finder->in(__DIR__)
1170
-            ->directories()
1171
-            ->name('Fixtures')
1172
-            ->notContains('abc');
1173
-        $this->assertIterator([], $finder);
1174
-    }
1175
-
1176
-    /**
1177
-     * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
1178
-     * with inner FilesystemIterator in an invalid state.
1179
-     *
1180
-     * @see https://bugs.php.net/68557
1181
-     */
1182
-    public function testMultipleLocations()
1183
-    {
1184
-        $locations = [
1185
-            self::$tmpDir.'/',
1186
-            self::$tmpDir.'/toto/',
1187
-        ];
1188
-
1189
-        // it is expected that there are test.py test.php in the tmpDir
1190
-        $finder = new Finder();
1191
-        $finder->in($locations)
1192
-            // the default flag IGNORE_DOT_FILES fixes the problem indirectly
1193
-            // so we set it to false for better isolation
1194
-            ->ignoreDotFiles(false)
1195
-            ->depth('< 1')->name('test.php');
1196
-
1197
-        $this->assertCount(1, $finder);
1198
-    }
1199
-
1200
-    /**
1201
-     * Searching in multiple locations with sub directories involves
1202
-     * AppendIterator which does an unnecessary rewind which leaves
1203
-     * FilterIterator with inner FilesystemIterator in an invalid state.
1204
-     *
1205
-     * @see https://bugs.php.net/68557
1206
-     */
1207
-    public function testMultipleLocationsWithSubDirectories()
1208
-    {
1209
-        $locations = [
1210
-            __DIR__.'/Fixtures/one',
1211
-            self::$tmpDir.\DIRECTORY_SEPARATOR.'toto',
1212
-        ];
1213
-
1214
-        $finder = $this->buildFinder();
1215
-        $finder->in($locations)->depth('< 10')->name('*.neon');
1216
-
1217
-        $expected = [
1218
-            __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
1219
-            __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
1220
-        ];
1221
-
1222
-        $this->assertIterator($expected, $finder);
1223
-        $this->assertIteratorInForeach($expected, $finder);
1224
-    }
1225
-
1226
-    /**
1227
-     * Iterator keys must be the file pathname.
1228
-     */
1229
-    public function testIteratorKeys()
1230
-    {
1231
-        $finder = $this->buildFinder()->in(self::$tmpDir);
1232
-        foreach ($finder as $key => $file) {
1233
-            $this->assertEquals($file->getPathname(), $key);
1234
-        }
1235
-    }
1236
-
1237
-    public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
1238
-    {
1239
-        $finder = $this->buildFinder();
1240
-        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
1241
-            ->path('/^dir/');
1242
-
1243
-        $expected = ['r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir', 'r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir'.\DIRECTORY_SEPARATOR.'bar.dat'];
1244
-        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1245
-    }
1246
-
1247
-    public function getContainsTestData()
1248
-    {
1249
-        return [
1250
-            ['', '', []],
1251
-            ['foo', 'bar', []],
1252
-            ['', 'foobar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
1253
-            ['lorem ipsum dolor sit amet', 'foobar', ['lorem.txt']],
1254
-            ['sit', 'bar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
1255
-            ['dolor sit amet', '@^L@m', ['dolor.txt', 'ipsum.txt']],
1256
-            ['/^lorem ipsum dolor sit amet$/m', 'foobar', ['lorem.txt']],
1257
-            ['lorem', 'foobar', ['lorem.txt']],
1258
-            ['', 'lorem', ['dolor.txt', 'ipsum.txt']],
1259
-            ['ipsum dolor sit amet', '/^IPSUM/m', ['lorem.txt']],
1260
-            [['lorem', 'dolor'], [], ['lorem.txt', 'ipsum.txt', 'dolor.txt']],
1261
-            ['', ['lorem', 'ipsum'], ['dolor.txt']],
1262
-        ];
1263
-    }
1264
-
1265
-    public function getRegexNameTestData()
1266
-    {
1267
-        return [
1268
-            ['~.*t\\.p.+~i'],
1269
-            ['~t.*s~i'],
1270
-        ];
1271
-    }
1272
-
1273
-    /**
1274
-     * @dataProvider getTestPathData
1275
-     */
1276
-    public function testPath($matchPatterns, $noMatchPatterns, array $expected)
1277
-    {
1278
-        $finder = $this->buildFinder();
1279
-        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
1280
-            ->path($matchPatterns)
1281
-            ->notPath($noMatchPatterns);
1282
-
1283
-        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1284
-    }
1285
-
1286
-    public function getTestPathData()
1287
-    {
1288
-        return [
1289
-            ['', '', []],
1290
-            ['/^A\/B\/C/', '/C$/',
1291
-                ['A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat'],
1292
-            ],
1293
-            ['/^A\/B/', 'foobar',
1294
-                [
1295
-                    'A'.\DIRECTORY_SEPARATOR.'B',
1296
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1297
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1298
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1299
-                ],
1300
-            ],
1301
-            ['A/B/C', 'foobar',
1302
-                [
1303
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1304
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1305
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1306
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
1307
-                ],
1308
-            ],
1309
-            ['A/B', 'foobar',
1310
-                [
1311
-                    //dirs
1312
-                    'A'.\DIRECTORY_SEPARATOR.'B',
1313
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1314
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B',
1315
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1316
-                    //files
1317
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1318
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1319
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy',
1320
-                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
1321
-                ],
1322
-            ],
1323
-            ['/^with space\//', 'foobar',
1324
-                [
1325
-                    'with space'.\DIRECTORY_SEPARATOR.'foo.txt',
1326
-                ],
1327
-            ],
1328
-            [
1329
-                '/^A/',
1330
-                ['a.dat', 'abc.dat'],
1331
-                [
1332
-                    'A',
1333
-                    'A'.\DIRECTORY_SEPARATOR.'B',
1334
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1335
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1336
-                ],
1337
-            ],
1338
-            [
1339
-                ['/^A/', 'one'],
1340
-                'foobar',
1341
-                [
1342
-                    'A',
1343
-                    'A'.\DIRECTORY_SEPARATOR.'B',
1344
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1345
-                    'A'.\DIRECTORY_SEPARATOR.'a.dat',
1346
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1347
-                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1348
-                    'one',
1349
-                    'one'.\DIRECTORY_SEPARATOR.'a',
1350
-                    'one'.\DIRECTORY_SEPARATOR.'b',
1351
-                    'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
1352
-                    'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
1353
-                ],
1354
-            ],
1355
-        ];
1356
-    }
1357
-
1358
-    public function testAccessDeniedException()
1359
-    {
1360
-        if ('\\' === \DIRECTORY_SEPARATOR) {
1361
-            $this->markTestSkipped('chmod is not supported on Windows');
1362
-        }
1363
-
1364
-        $finder = $this->buildFinder();
1365
-        $finder->files()->in(self::$tmpDir);
1366
-
1367
-        // make 'foo' directory non-readable
1368
-        $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
1369
-        chmod($testDir, 0333);
1370
-
1371
-        if (false === $couldRead = is_readable($testDir)) {
1372
-            try {
1373
-                $this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
1374
-                $this->fail('Finder should throw an exception when opening a non-readable directory.');
1375
-            } catch (\Exception $e) {
1376
-                $expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
1377
-                if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {
1378
-                    $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1379
-                }
1380
-
1381
-                if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
1382
-                    $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1383
-                }
1384
-
1385
-                $this->assertInstanceOf($expectedExceptionClass, $e);
1386
-            }
1387
-        }
1388
-
1389
-        // restore original permissions
1390
-        chmod($testDir, 0777);
1391
-        clearstatcache(true, $testDir);
1392
-
1393
-        if ($couldRead) {
1394
-            $this->markTestSkipped('could read test files while test requires unreadable');
1395
-        }
1396
-    }
1397
-
1398
-    public function testIgnoredAccessDeniedException()
1399
-    {
1400
-        if ('\\' === \DIRECTORY_SEPARATOR) {
1401
-            $this->markTestSkipped('chmod is not supported on Windows');
1402
-        }
1403
-
1404
-        $finder = $this->buildFinder();
1405
-        $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
1406
-
1407
-        // make 'foo' directory non-readable
1408
-        $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
1409
-        chmod($testDir, 0333);
1410
-
1411
-        if (false === ($couldRead = is_readable($testDir))) {
1412
-            $this->assertIterator($this->toAbsolute([
1413
-                'foo bar',
1414
-                'test.php',
1415
-                'test.py',
1416
-                'qux/baz_100_1.py',
1417
-                'qux/baz_1_2.py',
1418
-                'qux_0_1.php',
1419
-                'qux_1000_1.php',
1420
-                'qux_1002_0.php',
1421
-                'qux_10_2.php',
1422
-                'qux_12_0.php',
1423
-                'qux_2_0.php',
1424
-                ]
1425
-            ), $finder->getIterator());
1426
-        }
1427
-
1428
-        // restore original permissions
1429
-        chmod($testDir, 0777);
1430
-        clearstatcache(true, $testDir);
1431
-
1432
-        if ($couldRead) {
1433
-            $this->markTestSkipped('could read test files while test requires unreadable');
1434
-        }
1435
-    }
1436
-
1437
-    /**
1438
-     * @group legacy
1439
-     * @expectedDeprecation The "Symfony\Component\Finder\Finder::sortByName()" method will have a new "bool $useNaturalSort = false" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
1440
-     */
1441
-    public function testInheritedClassCallSortByNameWithNoArguments()
1442
-    {
1443
-        $finderChild = new ClassThatInheritFinder();
1444
-        $finderChild->sortByName();
1445
-    }
1446
-
1447
-    protected function buildFinder()
1448
-    {
1449
-        return Finder::create();
1450
-    }
1451
-}
1452
-
1453
-class ClassThatInheritFinder extends Finder
1454
-{
1455
-    public function sortByName()
1456
-    {
1457
-        parent::sortByName();
1458
-    }
1459
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1459 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+namespace Symfony\Component\Finder\Tests;
13
+
14
+use Symfony\Component\Finder\Finder;
15
+
16
+class FinderTest extends Iterator\RealIteratorTestCase
17
+{
18
+    public function testCreate()
19
+    {
20
+        $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
21
+    }
22
+
23
+    public function testDirectories()
24
+    {
25
+        $finder = $this->buildFinder();
26
+        $this->assertSame($finder, $finder->directories());
27
+        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto']), $finder->in(self::$tmpDir)->getIterator());
28
+
29
+        $finder = $this->buildFinder();
30
+        $finder->directories();
31
+        $finder->files();
32
+        $finder->directories();
33
+        $this->assertIterator($this->toAbsolute(['foo', 'qux', 'toto']), $finder->in(self::$tmpDir)->getIterator());
34
+    }
35
+
36
+    public function testFiles()
37
+    {
38
+        $finder = $this->buildFinder();
39
+        $this->assertSame($finder, $finder->files());
40
+        $this->assertIterator($this->toAbsolute(['foo/bar.tmp',
41
+            'test.php',
42
+            'test.py',
43
+            'foo bar',
44
+            'qux/baz_100_1.py',
45
+            'qux/baz_1_2.py',
46
+            'qux_0_1.php',
47
+            'qux_1000_1.php',
48
+            'qux_1002_0.php',
49
+            'qux_10_2.php',
50
+            'qux_12_0.php',
51
+            'qux_2_0.php',
52
+        ]), $finder->in(self::$tmpDir)->getIterator());
53
+
54
+        $finder = $this->buildFinder();
55
+        $finder->files();
56
+        $finder->directories();
57
+        $finder->files();
58
+        $this->assertIterator($this->toAbsolute(['foo/bar.tmp',
59
+            'test.php',
60
+            'test.py',
61
+            'foo bar',
62
+            'qux/baz_100_1.py',
63
+            'qux/baz_1_2.py',
64
+            'qux_0_1.php',
65
+            'qux_1000_1.php',
66
+            'qux_1002_0.php',
67
+            'qux_10_2.php',
68
+            'qux_12_0.php',
69
+            'qux_2_0.php',
70
+        ]), $finder->in(self::$tmpDir)->getIterator());
71
+    }
72
+
73
+    public function testRemoveTrailingSlash()
74
+    {
75
+        $finder = $this->buildFinder();
76
+
77
+        $expected = $this->toAbsolute([
78
+            'foo/bar.tmp',
79
+            'test.php',
80
+            'test.py',
81
+            'foo bar',
82
+            'qux/baz_100_1.py',
83
+            'qux/baz_1_2.py',
84
+            'qux_0_1.php',
85
+            'qux_1000_1.php',
86
+            'qux_1002_0.php',
87
+            'qux_10_2.php',
88
+            'qux_12_0.php',
89
+            'qux_2_0.php',
90
+        ]);
91
+        $in = self::$tmpDir.'//';
92
+
93
+        $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
94
+    }
95
+
96
+    public function testSymlinksNotResolved()
97
+    {
98
+        if ('\\' === \DIRECTORY_SEPARATOR) {
99
+            $this->markTestSkipped('symlinks are not supported on Windows');
100
+        }
101
+
102
+        $finder = $this->buildFinder();
103
+
104
+        symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
105
+        $expected = $this->toAbsolute(['baz/bar.tmp']);
106
+        $in = self::$tmpDir.'/baz/';
107
+        try {
108
+            $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
109
+            unlink($this->toAbsolute('baz'));
110
+        } catch (\Exception $e) {
111
+            unlink($this->toAbsolute('baz'));
112
+            throw $e;
113
+        }
114
+    }
115
+
116
+    public function testBackPathNotNormalized()
117
+    {
118
+        $finder = $this->buildFinder();
119
+
120
+        $expected = $this->toAbsolute(['foo/../foo/bar.tmp']);
121
+        $in = self::$tmpDir.'/foo/../foo/';
122
+        $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
123
+    }
124
+
125
+    public function testDepth()
126
+    {
127
+        $finder = $this->buildFinder();
128
+        $this->assertSame($finder, $finder->depth('< 1'));
129
+        $this->assertIterator($this->toAbsolute(['foo',
130
+            'test.php',
131
+            'test.py',
132
+            'toto',
133
+            'foo bar',
134
+            'qux',
135
+            'qux_0_1.php',
136
+            'qux_1000_1.php',
137
+            'qux_1002_0.php',
138
+            'qux_10_2.php',
139
+            'qux_12_0.php',
140
+            'qux_2_0.php',
141
+        ]), $finder->in(self::$tmpDir)->getIterator());
142
+
143
+        $finder = $this->buildFinder();
144
+        $this->assertSame($finder, $finder->depth('<= 0'));
145
+        $this->assertIterator($this->toAbsolute(['foo',
146
+            'test.php',
147
+            'test.py',
148
+            'toto',
149
+            'foo bar',
150
+            'qux',
151
+            'qux_0_1.php',
152
+            'qux_1000_1.php',
153
+            'qux_1002_0.php',
154
+            'qux_10_2.php',
155
+            'qux_12_0.php',
156
+            'qux_2_0.php',
157
+        ]), $finder->in(self::$tmpDir)->getIterator());
158
+
159
+        $finder = $this->buildFinder();
160
+        $this->assertSame($finder, $finder->depth('>= 1'));
161
+        $this->assertIterator($this->toAbsolute([
162
+            'foo/bar.tmp',
163
+            'qux/baz_100_1.py',
164
+            'qux/baz_1_2.py',
165
+        ]), $finder->in(self::$tmpDir)->getIterator());
166
+
167
+        $finder = $this->buildFinder();
168
+        $finder->depth('< 1')->depth('>= 1');
169
+        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
170
+    }
171
+
172
+    public function testDepthWithArrayParam()
173
+    {
174
+        $finder = $this->buildFinder();
175
+        $finder->depth(['>= 1', '< 2']);
176
+        $this->assertIterator($this->toAbsolute([
177
+            'foo/bar.tmp',
178
+            'qux/baz_100_1.py',
179
+            'qux/baz_1_2.py',
180
+        ]), $finder->in(self::$tmpDir)->getIterator());
181
+    }
182
+
183
+    public function testName()
184
+    {
185
+        $finder = $this->buildFinder();
186
+        $this->assertSame($finder, $finder->name('*.php'));
187
+        $this->assertIterator($this->toAbsolute([
188
+            'test.php',
189
+            'qux_0_1.php',
190
+            'qux_1000_1.php',
191
+            'qux_1002_0.php',
192
+            'qux_10_2.php',
193
+            'qux_12_0.php',
194
+            'qux_2_0.php',
195
+        ]), $finder->in(self::$tmpDir)->getIterator());
196
+
197
+        $finder = $this->buildFinder();
198
+        $finder->name('test.ph*');
199
+        $finder->name('test.py');
200
+        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
201
+
202
+        $finder = $this->buildFinder();
203
+        $finder->name('~^test~i');
204
+        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
205
+
206
+        $finder = $this->buildFinder();
207
+        $finder->name('~\\.php$~i');
208
+        $this->assertIterator($this->toAbsolute([
209
+            'test.php',
210
+            'qux_0_1.php',
211
+            'qux_1000_1.php',
212
+            'qux_1002_0.php',
213
+            'qux_10_2.php',
214
+            'qux_12_0.php',
215
+            'qux_2_0.php',
216
+        ]), $finder->in(self::$tmpDir)->getIterator());
217
+
218
+        $finder = $this->buildFinder();
219
+        $finder->name('test.p{hp,y}');
220
+        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
221
+    }
222
+
223
+    public function testNameWithArrayParam()
224
+    {
225
+        $finder = $this->buildFinder();
226
+        $finder->name(['test.php', 'test.py']);
227
+        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
228
+    }
229
+
230
+    public function testNotName()
231
+    {
232
+        $finder = $this->buildFinder();
233
+        $this->assertSame($finder, $finder->notName('*.php'));
234
+        $this->assertIterator($this->toAbsolute([
235
+            'foo',
236
+            'foo/bar.tmp',
237
+            'test.py',
238
+            'toto',
239
+            'foo bar',
240
+            'qux',
241
+            'qux/baz_100_1.py',
242
+            'qux/baz_1_2.py',
243
+        ]), $finder->in(self::$tmpDir)->getIterator());
244
+
245
+        $finder = $this->buildFinder();
246
+        $finder->notName('*.php');
247
+        $finder->notName('*.py');
248
+        $this->assertIterator($this->toAbsolute([
249
+            'foo',
250
+            'foo/bar.tmp',
251
+            'toto',
252
+            'foo bar',
253
+            'qux',
254
+        ]), $finder->in(self::$tmpDir)->getIterator());
255
+
256
+        $finder = $this->buildFinder();
257
+        $finder->name('test.ph*');
258
+        $finder->name('test.py');
259
+        $finder->notName('*.php');
260
+        $finder->notName('*.py');
261
+        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
262
+
263
+        $finder = $this->buildFinder();
264
+        $finder->name('test.ph*');
265
+        $finder->name('test.py');
266
+        $finder->notName('*.p{hp,y}');
267
+        $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
268
+    }
269
+
270
+    public function testNotNameWithArrayParam()
271
+    {
272
+        $finder = $this->buildFinder();
273
+        $finder->notName(['*.php', '*.py']);
274
+        $this->assertIterator($this->toAbsolute([
275
+            'foo',
276
+            'foo/bar.tmp',
277
+            'toto',
278
+            'foo bar',
279
+            'qux',
280
+        ]), $finder->in(self::$tmpDir)->getIterator());
281
+    }
282
+
283
+    /**
284
+     * @dataProvider getRegexNameTestData
285
+     */
286
+    public function testRegexName($regex)
287
+    {
288
+        $finder = $this->buildFinder();
289
+        $finder->name($regex);
290
+        $this->assertIterator($this->toAbsolute([
291
+            'test.py',
292
+            'test.php',
293
+        ]), $finder->in(self::$tmpDir)->getIterator());
294
+    }
295
+
296
+    public function testSize()
297
+    {
298
+        $finder = $this->buildFinder();
299
+        $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
300
+        $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
301
+    }
302
+
303
+    public function testSizeWithArrayParam()
304
+    {
305
+        $finder = $this->buildFinder();
306
+        $this->assertSame($finder, $finder->files()->size(['< 1K', '> 500']));
307
+        $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
308
+    }
309
+
310
+    public function testDate()
311
+    {
312
+        $finder = $this->buildFinder();
313
+        $this->assertSame($finder, $finder->files()->date('until last month'));
314
+        $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
315
+    }
316
+
317
+    public function testDateWithArrayParam()
318
+    {
319
+        $finder = $this->buildFinder();
320
+        $this->assertSame($finder, $finder->files()->date(['>= 2005-10-15', 'until last month']));
321
+        $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
322
+    }
323
+
324
+    public function testExclude()
325
+    {
326
+        $finder = $this->buildFinder();
327
+        $this->assertSame($finder, $finder->exclude('foo'));
328
+        $this->assertIterator($this->toAbsolute([
329
+            'test.php',
330
+            'test.py',
331
+            'toto',
332
+            'foo bar',
333
+            'qux',
334
+            'qux/baz_100_1.py',
335
+            'qux/baz_1_2.py',
336
+            'qux_0_1.php',
337
+            'qux_1000_1.php',
338
+            'qux_1002_0.php',
339
+            'qux_10_2.php',
340
+            'qux_12_0.php',
341
+            'qux_2_0.php',
342
+        ]), $finder->in(self::$tmpDir)->getIterator());
343
+    }
344
+
345
+    public function testIgnoreVCS()
346
+    {
347
+        $finder = $this->buildFinder();
348
+        $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
349
+        $this->assertIterator($this->toAbsolute([
350
+            '.gitignore',
351
+            '.git',
352
+            'foo',
353
+            'foo/bar.tmp',
354
+            'test.php',
355
+            'test.py',
356
+            'toto',
357
+            'toto/.git',
358
+            '.bar',
359
+            '.foo',
360
+            '.foo/.bar',
361
+            '.foo/bar',
362
+            'foo bar',
363
+            'qux',
364
+            'qux/baz_100_1.py',
365
+            'qux/baz_1_2.py',
366
+            'qux_0_1.php',
367
+            'qux_1000_1.php',
368
+            'qux_1002_0.php',
369
+            'qux_10_2.php',
370
+            'qux_12_0.php',
371
+            'qux_2_0.php',
372
+        ]), $finder->in(self::$tmpDir)->getIterator());
373
+
374
+        $finder = $this->buildFinder();
375
+        $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
376
+        $this->assertIterator($this->toAbsolute([
377
+            '.gitignore',
378
+            '.git',
379
+            'foo',
380
+            'foo/bar.tmp',
381
+            'test.php',
382
+            'test.py',
383
+            'toto',
384
+            'toto/.git',
385
+            '.bar',
386
+            '.foo',
387
+            '.foo/.bar',
388
+            '.foo/bar',
389
+            'foo bar',
390
+            'qux',
391
+            'qux/baz_100_1.py',
392
+            'qux/baz_1_2.py',
393
+            'qux_0_1.php',
394
+            'qux_1000_1.php',
395
+            'qux_1002_0.php',
396
+            'qux_10_2.php',
397
+            'qux_12_0.php',
398
+            'qux_2_0.php',
399
+        ]), $finder->in(self::$tmpDir)->getIterator());
400
+
401
+        $finder = $this->buildFinder();
402
+        $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
403
+        $this->assertIterator($this->toAbsolute([
404
+            '.gitignore',
405
+            'foo',
406
+            'foo/bar.tmp',
407
+            'test.php',
408
+            'test.py',
409
+            'toto',
410
+            '.bar',
411
+            '.foo',
412
+            '.foo/.bar',
413
+            '.foo/bar',
414
+            'foo bar',
415
+            'qux',
416
+            'qux/baz_100_1.py',
417
+            'qux/baz_1_2.py',
418
+            'qux_0_1.php',
419
+            'qux_1000_1.php',
420
+            'qux_1002_0.php',
421
+            'qux_10_2.php',
422
+            'qux_12_0.php',
423
+            'qux_2_0.php',
424
+        ]), $finder->in(self::$tmpDir)->getIterator());
425
+    }
426
+
427
+    public function testIgnoreVCSIgnored()
428
+    {
429
+        $finder = $this->buildFinder();
430
+        $this->assertSame(
431
+            $finder,
432
+            $finder
433
+                ->ignoreVCS(true)
434
+                ->ignoreDotFiles(true)
435
+                ->ignoreVCSIgnored(true)
436
+        );
437
+        $this->assertIterator($this->toAbsolute([
438
+            'foo',
439
+            'foo/bar.tmp',
440
+            'test.py',
441
+            'toto',
442
+            'foo bar',
443
+            'qux',
444
+            'qux/baz_100_1.py',
445
+            'qux/baz_1_2.py',
446
+        ]), $finder->in(self::$tmpDir)->getIterator());
447
+    }
448
+
449
+    public function testIgnoreVCSCanBeDisabledAfterFirstIteration()
450
+    {
451
+        $finder = $this->buildFinder();
452
+        $finder->in(self::$tmpDir);
453
+        $finder->ignoreDotFiles(false);
454
+
455
+        $this->assertIterator($this->toAbsolute([
456
+            '.gitignore',
457
+            'foo',
458
+            'foo/bar.tmp',
459
+            'qux',
460
+            'qux/baz_100_1.py',
461
+            'qux/baz_1_2.py',
462
+            'qux_0_1.php',
463
+            'qux_1000_1.php',
464
+            'qux_1002_0.php',
465
+            'qux_10_2.php',
466
+            'qux_12_0.php',
467
+            'qux_2_0.php',
468
+            'test.php',
469
+            'test.py',
470
+            'toto',
471
+            '.bar',
472
+            '.foo',
473
+            '.foo/.bar',
474
+            '.foo/bar',
475
+            'foo bar',
476
+        ]), $finder->getIterator());
477
+
478
+        $finder->ignoreVCS(false);
479
+        $this->assertIterator($this->toAbsolute([
480
+            '.gitignore',
481
+            '.git',
482
+            'foo',
483
+            'foo/bar.tmp',
484
+            'qux',
485
+            'qux/baz_100_1.py',
486
+            'qux/baz_1_2.py',
487
+            'qux_0_1.php',
488
+            'qux_1000_1.php',
489
+            'qux_1002_0.php',
490
+            'qux_10_2.php',
491
+            'qux_12_0.php',
492
+            'qux_2_0.php',
493
+            'test.php',
494
+            'test.py',
495
+            'toto',
496
+            'toto/.git',
497
+            '.bar',
498
+            '.foo',
499
+            '.foo/.bar',
500
+            '.foo/bar',
501
+            'foo bar',
502
+        ]), $finder->getIterator());
503
+    }
504
+
505
+    public function testIgnoreDotFiles()
506
+    {
507
+        $finder = $this->buildFinder();
508
+        $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
509
+        $this->assertIterator($this->toAbsolute([
510
+            '.gitignore',
511
+            '.git',
512
+            '.bar',
513
+            '.foo',
514
+            '.foo/.bar',
515
+            '.foo/bar',
516
+            'foo',
517
+            'foo/bar.tmp',
518
+            'test.php',
519
+            'test.py',
520
+            'toto',
521
+            'toto/.git',
522
+            'foo bar',
523
+            'qux',
524
+            'qux/baz_100_1.py',
525
+            'qux/baz_1_2.py',
526
+            'qux_0_1.php',
527
+            'qux_1000_1.php',
528
+            'qux_1002_0.php',
529
+            'qux_10_2.php',
530
+            'qux_12_0.php',
531
+            'qux_2_0.php',
532
+        ]), $finder->in(self::$tmpDir)->getIterator());
533
+
534
+        $finder = $this->buildFinder();
535
+        $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
536
+        $this->assertIterator($this->toAbsolute([
537
+            '.gitignore',
538
+            '.git',
539
+            '.bar',
540
+            '.foo',
541
+            '.foo/.bar',
542
+            '.foo/bar',
543
+            'foo',
544
+            'foo/bar.tmp',
545
+            'test.php',
546
+            'test.py',
547
+            'toto',
548
+            'toto/.git',
549
+            'foo bar',
550
+            'qux',
551
+            'qux/baz_100_1.py',
552
+            'qux/baz_1_2.py',
553
+            'qux_0_1.php',
554
+            'qux_1000_1.php',
555
+            'qux_1002_0.php',
556
+            'qux_10_2.php',
557
+            'qux_12_0.php',
558
+            'qux_2_0.php',
559
+        ]), $finder->in(self::$tmpDir)->getIterator());
560
+
561
+        $finder = $this->buildFinder();
562
+        $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
563
+        $this->assertIterator($this->toAbsolute([
564
+            'foo',
565
+            'foo/bar.tmp',
566
+            'test.php',
567
+            'test.py',
568
+            'toto',
569
+            'foo bar',
570
+            'qux',
571
+            'qux/baz_100_1.py',
572
+            'qux/baz_1_2.py',
573
+            'qux_0_1.php',
574
+            'qux_1000_1.php',
575
+            'qux_1002_0.php',
576
+            'qux_10_2.php',
577
+            'qux_12_0.php',
578
+            'qux_2_0.php',
579
+        ]), $finder->in(self::$tmpDir)->getIterator());
580
+    }
581
+
582
+    public function testIgnoreDotFilesCanBeDisabledAfterFirstIteration()
583
+    {
584
+        $finder = $this->buildFinder();
585
+        $finder->in(self::$tmpDir);
586
+
587
+        $this->assertIterator($this->toAbsolute([
588
+            'foo',
589
+            'foo/bar.tmp',
590
+            'qux',
591
+            'qux/baz_100_1.py',
592
+            'qux/baz_1_2.py',
593
+            'qux_0_1.php',
594
+            'qux_1000_1.php',
595
+            'qux_1002_0.php',
596
+            'qux_10_2.php',
597
+            'qux_12_0.php',
598
+            'qux_2_0.php',
599
+            'test.php',
600
+            'test.py',
601
+            'toto',
602
+            'foo bar',
603
+        ]), $finder->getIterator());
604
+
605
+        $finder->ignoreDotFiles(false);
606
+        $this->assertIterator($this->toAbsolute([
607
+            '.gitignore',
608
+            'foo',
609
+            'foo/bar.tmp',
610
+            'qux',
611
+            'qux/baz_100_1.py',
612
+            'qux/baz_1_2.py',
613
+            'qux_0_1.php',
614
+            'qux_1000_1.php',
615
+            'qux_1002_0.php',
616
+            'qux_10_2.php',
617
+            'qux_12_0.php',
618
+            'qux_2_0.php',
619
+            'test.php',
620
+            'test.py',
621
+            'toto',
622
+            '.bar',
623
+            '.foo',
624
+            '.foo/.bar',
625
+            '.foo/bar',
626
+            'foo bar',
627
+        ]), $finder->getIterator());
628
+    }
629
+
630
+    public function testSortByName()
631
+    {
632
+        $finder = $this->buildFinder();
633
+        $this->assertSame($finder, $finder->sortByName());
634
+        $this->assertIterator($this->toAbsolute([
635
+            'foo',
636
+            'foo bar',
637
+            'foo/bar.tmp',
638
+            'qux',
639
+            'qux/baz_100_1.py',
640
+            'qux/baz_1_2.py',
641
+            'qux_0_1.php',
642
+            'qux_1000_1.php',
643
+            'qux_1002_0.php',
644
+            'qux_10_2.php',
645
+            'qux_12_0.php',
646
+            'qux_2_0.php',
647
+            'test.php',
648
+            'test.py',
649
+            'toto',
650
+        ]), $finder->in(self::$tmpDir)->getIterator());
651
+    }
652
+
653
+    public function testSortByType()
654
+    {
655
+        $finder = $this->buildFinder();
656
+        $this->assertSame($finder, $finder->sortByType());
657
+        $this->assertIterator($this->toAbsolute([
658
+            'foo',
659
+            'foo bar',
660
+            'toto',
661
+            'foo/bar.tmp',
662
+            'test.php',
663
+            'test.py',
664
+            'qux',
665
+            'qux/baz_100_1.py',
666
+            'qux/baz_1_2.py',
667
+            'qux_0_1.php',
668
+            'qux_1000_1.php',
669
+            'qux_1002_0.php',
670
+            'qux_10_2.php',
671
+            'qux_12_0.php',
672
+            'qux_2_0.php',
673
+        ]), $finder->in(self::$tmpDir)->getIterator());
674
+    }
675
+
676
+    public function testSortByAccessedTime()
677
+    {
678
+        $finder = $this->buildFinder();
679
+        $this->assertSame($finder, $finder->sortByAccessedTime());
680
+        $this->assertIterator($this->toAbsolute([
681
+            'foo/bar.tmp',
682
+            'test.php',
683
+            'toto',
684
+            'test.py',
685
+            'foo',
686
+            'foo bar',
687
+            'qux',
688
+            'qux/baz_100_1.py',
689
+            'qux/baz_1_2.py',
690
+            'qux_0_1.php',
691
+            'qux_1000_1.php',
692
+            'qux_1002_0.php',
693
+            'qux_10_2.php',
694
+            'qux_12_0.php',
695
+            'qux_2_0.php',
696
+        ]), $finder->in(self::$tmpDir)->getIterator());
697
+    }
698
+
699
+    public function testSortByChangedTime()
700
+    {
701
+        $finder = $this->buildFinder();
702
+        $this->assertSame($finder, $finder->sortByChangedTime());
703
+        $this->assertIterator($this->toAbsolute([
704
+            'toto',
705
+            'test.py',
706
+            'test.php',
707
+            'foo/bar.tmp',
708
+            'foo',
709
+            'foo bar',
710
+            'qux',
711
+            'qux/baz_100_1.py',
712
+            'qux/baz_1_2.py',
713
+            'qux_0_1.php',
714
+            'qux_1000_1.php',
715
+            'qux_1002_0.php',
716
+            'qux_10_2.php',
717
+            'qux_12_0.php',
718
+            'qux_2_0.php',
719
+        ]), $finder->in(self::$tmpDir)->getIterator());
720
+    }
721
+
722
+    public function testSortByModifiedTime()
723
+    {
724
+        $finder = $this->buildFinder();
725
+        $this->assertSame($finder, $finder->sortByModifiedTime());
726
+        $this->assertIterator($this->toAbsolute([
727
+            'foo/bar.tmp',
728
+            'test.php',
729
+            'toto',
730
+            'test.py',
731
+            'foo',
732
+            'foo bar',
733
+            'qux',
734
+            'qux/baz_100_1.py',
735
+            'qux/baz_1_2.py',
736
+            'qux_0_1.php',
737
+            'qux_1000_1.php',
738
+            'qux_1002_0.php',
739
+            'qux_10_2.php',
740
+            'qux_12_0.php',
741
+            'qux_2_0.php',
742
+        ]), $finder->in(self::$tmpDir)->getIterator());
743
+    }
744
+
745
+    public function testReverseSorting()
746
+    {
747
+        $finder = $this->buildFinder();
748
+        $this->assertSame($finder, $finder->sortByName());
749
+        $this->assertSame($finder, $finder->reverseSorting());
750
+        $this->assertOrderedIteratorInForeach($this->toAbsolute([
751
+            'toto',
752
+            'test.py',
753
+            'test.php',
754
+            'qux_2_0.php',
755
+            'qux_12_0.php',
756
+            'qux_10_2.php',
757
+            'qux_1002_0.php',
758
+            'qux_1000_1.php',
759
+            'qux_0_1.php',
760
+            'qux/baz_1_2.py',
761
+            'qux/baz_100_1.py',
762
+            'qux',
763
+            'foo/bar.tmp',
764
+            'foo bar',
765
+            'foo',
766
+        ]), $finder->in(self::$tmpDir)->getIterator());
767
+    }
768
+
769
+    public function testSortByNameNatural()
770
+    {
771
+        $finder = $this->buildFinder();
772
+        $this->assertSame($finder, $finder->sortByName(true));
773
+        $this->assertIterator($this->toAbsolute([
774
+            'foo',
775
+            'foo bar',
776
+            'foo/bar.tmp',
777
+            'qux',
778
+            'qux/baz_100_1.py',
779
+            'qux/baz_1_2.py',
780
+            'qux_0_1.php',
781
+            'qux_1000_1.php',
782
+            'qux_1002_0.php',
783
+            'qux_10_2.php',
784
+            'qux_12_0.php',
785
+            'qux_2_0.php',
786
+            'test.php',
787
+            'test.py',
788
+            'toto',
789
+        ]), $finder->in(self::$tmpDir)->getIterator());
790
+
791
+        $finder = $this->buildFinder();
792
+        $this->assertSame($finder, $finder->sortByName(false));
793
+        $this->assertIterator($this->toAbsolute([
794
+            'foo',
795
+            'foo bar',
796
+            'foo/bar.tmp',
797
+            'qux',
798
+            'qux/baz_100_1.py',
799
+            'qux/baz_1_2.py',
800
+            'qux_0_1.php',
801
+            'qux_1000_1.php',
802
+            'qux_1002_0.php',
803
+            'qux_10_2.php',
804
+            'qux_12_0.php',
805
+            'qux_2_0.php',
806
+            'test.php',
807
+            'test.py',
808
+            'toto',
809
+        ]), $finder->in(self::$tmpDir)->getIterator());
810
+    }
811
+
812
+    public function testSort()
813
+    {
814
+        $finder = $this->buildFinder();
815
+        $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
816
+        $this->assertIterator($this->toAbsolute([
817
+            'foo',
818
+            'foo bar',
819
+            'foo/bar.tmp',
820
+            'test.php',
821
+            'test.py',
822
+            'toto',
823
+            'qux',
824
+            'qux/baz_100_1.py',
825
+            'qux/baz_1_2.py',
826
+            'qux_0_1.php',
827
+            'qux_1000_1.php',
828
+            'qux_1002_0.php',
829
+            'qux_10_2.php',
830
+            'qux_12_0.php',
831
+            'qux_2_0.php',
832
+        ]), $finder->in(self::$tmpDir)->getIterator());
833
+    }
834
+
835
+    public function testFilter()
836
+    {
837
+        $finder = $this->buildFinder();
838
+        $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
839
+        $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
840
+    }
841
+
842
+    public function testFollowLinks()
843
+    {
844
+        if ('\\' == \DIRECTORY_SEPARATOR) {
845
+            $this->markTestSkipped('symlinks are not supported on Windows');
846
+        }
847
+
848
+        $finder = $this->buildFinder();
849
+        $this->assertSame($finder, $finder->followLinks());
850
+        $this->assertIterator($this->toAbsolute([
851
+            'foo',
852
+            'foo/bar.tmp',
853
+            'test.php',
854
+            'test.py',
855
+            'toto',
856
+            'foo bar',
857
+            'qux',
858
+            'qux/baz_100_1.py',
859
+            'qux/baz_1_2.py',
860
+            'qux_0_1.php',
861
+            'qux_1000_1.php',
862
+            'qux_1002_0.php',
863
+            'qux_10_2.php',
864
+            'qux_12_0.php',
865
+            'qux_2_0.php',
866
+        ]), $finder->in(self::$tmpDir)->getIterator());
867
+    }
868
+
869
+    public function testIn()
870
+    {
871
+        $finder = $this->buildFinder();
872
+        $iterator = $finder->files()->name('*.php')->depth('< 1')->in([self::$tmpDir, __DIR__])->getIterator();
873
+
874
+        $expected = [
875
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
876
+            __DIR__.\DIRECTORY_SEPARATOR.'GitignoreTest.php',
877
+            __DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
878
+            __DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
879
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_0_1.php',
880
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php',
881
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php',
882
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_10_2.php',
883
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_12_0.php',
884
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_2_0.php',
885
+        ];
886
+
887
+        $this->assertIterator($expected, $iterator);
888
+    }
889
+
890
+    /**
891
+     * @expectedException \Symfony\Component\Finder\Exception\DirectoryNotFoundException
892
+     */
893
+    public function testInWithNonExistentDirectory()
894
+    {
895
+        $finder = new Finder();
896
+        $finder->in('foobar');
897
+    }
898
+
899
+    /**
900
+     * @expectedException \InvalidArgumentException
901
+     */
902
+    public function testInWithNonExistentDirectoryLegacyException()
903
+    {
904
+        $finder = new Finder();
905
+        $finder->in('foobar');
906
+    }
907
+
908
+    public function testInWithGlob()
909
+    {
910
+        $finder = $this->buildFinder();
911
+        $finder->in([__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'])->getIterator();
912
+
913
+        $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
914
+    }
915
+
916
+    /**
917
+     * @expectedException \InvalidArgumentException
918
+     */
919
+    public function testInWithNonDirectoryGlob()
920
+    {
921
+        $finder = new Finder();
922
+        $finder->in(__DIR__.'/Fixtures/A/a*');
923
+    }
924
+
925
+    public function testInWithGlobBrace()
926
+    {
927
+        if (!\defined('GLOB_BRACE')) {
928
+            $this->markTestSkipped('Glob brace is not supported on this system.');
929
+        }
930
+
931
+        $finder = $this->buildFinder();
932
+        $finder->in([__DIR__.'/Fixtures/{A,copy/A}/B/C'])->getIterator();
933
+
934
+        $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
935
+    }
936
+
937
+    /**
938
+     * @expectedException \LogicException
939
+     */
940
+    public function testGetIteratorWithoutIn()
941
+    {
942
+        $finder = Finder::create();
943
+        $finder->getIterator();
944
+    }
945
+
946
+    public function testGetIterator()
947
+    {
948
+        $finder = $this->buildFinder();
949
+        $dirs = [];
950
+        foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
951
+            $dirs[] = (string) $dir;
952
+        }
953
+
954
+        $expected = $this->toAbsolute(['foo', 'qux', 'toto']);
955
+
956
+        sort($dirs);
957
+        sort($expected);
958
+
959
+        $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
960
+
961
+        $finder = $this->buildFinder();
962
+        $this->assertEquals(3, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
963
+
964
+        $finder = $this->buildFinder();
965
+        $a = iterator_to_array($finder->directories()->in(self::$tmpDir));
966
+        $a = array_values(array_map('strval', $a));
967
+        sort($a);
968
+        $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
969
+    }
970
+
971
+    public function testRelativePath()
972
+    {
973
+        $finder = $this->buildFinder()->in(self::$tmpDir);
974
+
975
+        $paths = [];
976
+
977
+        foreach ($finder as $file) {
978
+            $paths[] = $file->getRelativePath();
979
+        }
980
+
981
+        $ref = ['', '', '', '', '', '', '', '', '', '', '', 'foo', 'qux', 'qux', ''];
982
+
983
+        sort($ref);
984
+        sort($paths);
985
+
986
+        $this->assertEquals($ref, $paths);
987
+    }
988
+
989
+    public function testRelativePathname()
990
+    {
991
+        $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
992
+
993
+        $paths = [];
994
+
995
+        foreach ($finder as $file) {
996
+            $paths[] = $file->getRelativePathname();
997
+        }
998
+
999
+        $ref = [
1000
+            'test.php',
1001
+            'toto',
1002
+            'test.py',
1003
+            'foo',
1004
+            'foo'.\DIRECTORY_SEPARATOR.'bar.tmp',
1005
+            'foo bar',
1006
+            'qux',
1007
+            'qux'.\DIRECTORY_SEPARATOR.'baz_100_1.py',
1008
+            'qux'.\DIRECTORY_SEPARATOR.'baz_1_2.py',
1009
+            'qux_0_1.php',
1010
+            'qux_1000_1.php',
1011
+            'qux_1002_0.php',
1012
+            'qux_10_2.php',
1013
+            'qux_12_0.php',
1014
+            'qux_2_0.php',
1015
+        ];
1016
+
1017
+        sort($paths);
1018
+        sort($ref);
1019
+
1020
+        $this->assertEquals($ref, $paths);
1021
+    }
1022
+
1023
+    public function testGetFilenameWithoutExtension()
1024
+    {
1025
+        $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
1026
+
1027
+        $fileNames = [];
1028
+
1029
+        foreach ($finder as $file) {
1030
+            $fileNames[] = $file->getFilenameWithoutExtension();
1031
+        }
1032
+
1033
+        $ref = [
1034
+            'test',
1035
+            'toto',
1036
+            'test',
1037
+            'foo',
1038
+            'bar',
1039
+            'foo bar',
1040
+            'qux',
1041
+            'baz_100_1',
1042
+            'baz_1_2',
1043
+            'qux_0_1',
1044
+            'qux_1000_1',
1045
+            'qux_1002_0',
1046
+            'qux_10_2',
1047
+            'qux_12_0',
1048
+            'qux_2_0',
1049
+        ];
1050
+
1051
+        sort($fileNames);
1052
+        sort($ref);
1053
+
1054
+        $this->assertEquals($ref, $fileNames);
1055
+    }
1056
+
1057
+    public function testAppendWithAFinder()
1058
+    {
1059
+        $finder = $this->buildFinder();
1060
+        $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1061
+
1062
+        $finder1 = $this->buildFinder();
1063
+        $finder1->directories()->in(self::$tmpDir);
1064
+
1065
+        $finder = $finder->append($finder1);
1066
+
1067
+        $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'qux', 'toto']), $finder->getIterator());
1068
+    }
1069
+
1070
+    public function testAppendWithAnArray()
1071
+    {
1072
+        $finder = $this->buildFinder();
1073
+        $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1074
+
1075
+        $finder->append($this->toAbsolute(['foo', 'toto']));
1076
+
1077
+        $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
1078
+    }
1079
+
1080
+    public function testAppendReturnsAFinder()
1081
+    {
1082
+        $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append([]));
1083
+    }
1084
+
1085
+    public function testAppendDoesNotRequireIn()
1086
+    {
1087
+        $finder = $this->buildFinder();
1088
+        $finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
1089
+
1090
+        $finder1 = Finder::create()->append($finder);
1091
+
1092
+        $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
1093
+    }
1094
+
1095
+    public function testCountDirectories()
1096
+    {
1097
+        $directory = Finder::create()->directories()->in(self::$tmpDir);
1098
+        $i = 0;
1099
+
1100
+        foreach ($directory as $dir) {
1101
+            ++$i;
1102
+        }
1103
+
1104
+        $this->assertCount($i, $directory);
1105
+    }
1106
+
1107
+    public function testCountFiles()
1108
+    {
1109
+        $files = Finder::create()->files()->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
1110
+        $i = 0;
1111
+
1112
+        foreach ($files as $file) {
1113
+            ++$i;
1114
+        }
1115
+
1116
+        $this->assertCount($i, $files);
1117
+    }
1118
+
1119
+    /**
1120
+     * @expectedException \LogicException
1121
+     */
1122
+    public function testCountWithoutIn()
1123
+    {
1124
+        $finder = Finder::create()->files();
1125
+        \count($finder);
1126
+    }
1127
+
1128
+    public function testHasResults()
1129
+    {
1130
+        $finder = $this->buildFinder();
1131
+        $finder->in(__DIR__);
1132
+        $this->assertTrue($finder->hasResults());
1133
+    }
1134
+
1135
+    public function testNoResults()
1136
+    {
1137
+        $finder = $this->buildFinder();
1138
+        $finder->in(__DIR__)->name('DoesNotExist');
1139
+        $this->assertFalse($finder->hasResults());
1140
+    }
1141
+
1142
+    /**
1143
+     * @dataProvider getContainsTestData
1144
+     */
1145
+    public function testContains($matchPatterns, $noMatchPatterns, $expected)
1146
+    {
1147
+        $finder = $this->buildFinder();
1148
+        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
1149
+            ->name('*.txt')->sortByName()
1150
+            ->contains($matchPatterns)
1151
+            ->notContains($noMatchPatterns);
1152
+
1153
+        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1154
+    }
1155
+
1156
+    public function testContainsOnDirectory()
1157
+    {
1158
+        $finder = $this->buildFinder();
1159
+        $finder->in(__DIR__)
1160
+            ->directories()
1161
+            ->name('Fixtures')
1162
+            ->contains('abc');
1163
+        $this->assertIterator([], $finder);
1164
+    }
1165
+
1166
+    public function testNotContainsOnDirectory()
1167
+    {
1168
+        $finder = $this->buildFinder();
1169
+        $finder->in(__DIR__)
1170
+            ->directories()
1171
+            ->name('Fixtures')
1172
+            ->notContains('abc');
1173
+        $this->assertIterator([], $finder);
1174
+    }
1175
+
1176
+    /**
1177
+     * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
1178
+     * with inner FilesystemIterator in an invalid state.
1179
+     *
1180
+     * @see https://bugs.php.net/68557
1181
+     */
1182
+    public function testMultipleLocations()
1183
+    {
1184
+        $locations = [
1185
+            self::$tmpDir.'/',
1186
+            self::$tmpDir.'/toto/',
1187
+        ];
1188
+
1189
+        // it is expected that there are test.py test.php in the tmpDir
1190
+        $finder = new Finder();
1191
+        $finder->in($locations)
1192
+            // the default flag IGNORE_DOT_FILES fixes the problem indirectly
1193
+            // so we set it to false for better isolation
1194
+            ->ignoreDotFiles(false)
1195
+            ->depth('< 1')->name('test.php');
1196
+
1197
+        $this->assertCount(1, $finder);
1198
+    }
1199
+
1200
+    /**
1201
+     * Searching in multiple locations with sub directories involves
1202
+     * AppendIterator which does an unnecessary rewind which leaves
1203
+     * FilterIterator with inner FilesystemIterator in an invalid state.
1204
+     *
1205
+     * @see https://bugs.php.net/68557
1206
+     */
1207
+    public function testMultipleLocationsWithSubDirectories()
1208
+    {
1209
+        $locations = [
1210
+            __DIR__.'/Fixtures/one',
1211
+            self::$tmpDir.\DIRECTORY_SEPARATOR.'toto',
1212
+        ];
1213
+
1214
+        $finder = $this->buildFinder();
1215
+        $finder->in($locations)->depth('< 10')->name('*.neon');
1216
+
1217
+        $expected = [
1218
+            __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
1219
+            __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
1220
+        ];
1221
+
1222
+        $this->assertIterator($expected, $finder);
1223
+        $this->assertIteratorInForeach($expected, $finder);
1224
+    }
1225
+
1226
+    /**
1227
+     * Iterator keys must be the file pathname.
1228
+     */
1229
+    public function testIteratorKeys()
1230
+    {
1231
+        $finder = $this->buildFinder()->in(self::$tmpDir);
1232
+        foreach ($finder as $key => $file) {
1233
+            $this->assertEquals($file->getPathname(), $key);
1234
+        }
1235
+    }
1236
+
1237
+    public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
1238
+    {
1239
+        $finder = $this->buildFinder();
1240
+        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
1241
+            ->path('/^dir/');
1242
+
1243
+        $expected = ['r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir', 'r+e.gex[c]a(r)s'.\DIRECTORY_SEPARATOR.'dir'.\DIRECTORY_SEPARATOR.'bar.dat'];
1244
+        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1245
+    }
1246
+
1247
+    public function getContainsTestData()
1248
+    {
1249
+        return [
1250
+            ['', '', []],
1251
+            ['foo', 'bar', []],
1252
+            ['', 'foobar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
1253
+            ['lorem ipsum dolor sit amet', 'foobar', ['lorem.txt']],
1254
+            ['sit', 'bar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
1255
+            ['dolor sit amet', '@^L@m', ['dolor.txt', 'ipsum.txt']],
1256
+            ['/^lorem ipsum dolor sit amet$/m', 'foobar', ['lorem.txt']],
1257
+            ['lorem', 'foobar', ['lorem.txt']],
1258
+            ['', 'lorem', ['dolor.txt', 'ipsum.txt']],
1259
+            ['ipsum dolor sit amet', '/^IPSUM/m', ['lorem.txt']],
1260
+            [['lorem', 'dolor'], [], ['lorem.txt', 'ipsum.txt', 'dolor.txt']],
1261
+            ['', ['lorem', 'ipsum'], ['dolor.txt']],
1262
+        ];
1263
+    }
1264
+
1265
+    public function getRegexNameTestData()
1266
+    {
1267
+        return [
1268
+            ['~.*t\\.p.+~i'],
1269
+            ['~t.*s~i'],
1270
+        ];
1271
+    }
1272
+
1273
+    /**
1274
+     * @dataProvider getTestPathData
1275
+     */
1276
+    public function testPath($matchPatterns, $noMatchPatterns, array $expected)
1277
+    {
1278
+        $finder = $this->buildFinder();
1279
+        $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
1280
+            ->path($matchPatterns)
1281
+            ->notPath($noMatchPatterns);
1282
+
1283
+        $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
1284
+    }
1285
+
1286
+    public function getTestPathData()
1287
+    {
1288
+        return [
1289
+            ['', '', []],
1290
+            ['/^A\/B\/C/', '/C$/',
1291
+                ['A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat'],
1292
+            ],
1293
+            ['/^A\/B/', 'foobar',
1294
+                [
1295
+                    'A'.\DIRECTORY_SEPARATOR.'B',
1296
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1297
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1298
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1299
+                ],
1300
+            ],
1301
+            ['A/B/C', 'foobar',
1302
+                [
1303
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1304
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1305
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1306
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
1307
+                ],
1308
+            ],
1309
+            ['A/B', 'foobar',
1310
+                [
1311
+                    //dirs
1312
+                    'A'.\DIRECTORY_SEPARATOR.'B',
1313
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1314
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B',
1315
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1316
+                    //files
1317
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1318
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1319
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy',
1320
+                    'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
1321
+                ],
1322
+            ],
1323
+            ['/^with space\//', 'foobar',
1324
+                [
1325
+                    'with space'.\DIRECTORY_SEPARATOR.'foo.txt',
1326
+                ],
1327
+            ],
1328
+            [
1329
+                '/^A/',
1330
+                ['a.dat', 'abc.dat'],
1331
+                [
1332
+                    'A',
1333
+                    'A'.\DIRECTORY_SEPARATOR.'B',
1334
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1335
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1336
+                ],
1337
+            ],
1338
+            [
1339
+                ['/^A/', 'one'],
1340
+                'foobar',
1341
+                [
1342
+                    'A',
1343
+                    'A'.\DIRECTORY_SEPARATOR.'B',
1344
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
1345
+                    'A'.\DIRECTORY_SEPARATOR.'a.dat',
1346
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
1347
+                    'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
1348
+                    'one',
1349
+                    'one'.\DIRECTORY_SEPARATOR.'a',
1350
+                    'one'.\DIRECTORY_SEPARATOR.'b',
1351
+                    'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
1352
+                    'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
1353
+                ],
1354
+            ],
1355
+        ];
1356
+    }
1357
+
1358
+    public function testAccessDeniedException()
1359
+    {
1360
+        if ('\\' === \DIRECTORY_SEPARATOR) {
1361
+            $this->markTestSkipped('chmod is not supported on Windows');
1362
+        }
1363
+
1364
+        $finder = $this->buildFinder();
1365
+        $finder->files()->in(self::$tmpDir);
1366
+
1367
+        // make 'foo' directory non-readable
1368
+        $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
1369
+        chmod($testDir, 0333);
1370
+
1371
+        if (false === $couldRead = is_readable($testDir)) {
1372
+            try {
1373
+                $this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
1374
+                $this->fail('Finder should throw an exception when opening a non-readable directory.');
1375
+            } catch (\Exception $e) {
1376
+                $expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
1377
+                if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {
1378
+                    $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1379
+                }
1380
+
1381
+                if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
1382
+                    $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
1383
+                }
1384
+
1385
+                $this->assertInstanceOf($expectedExceptionClass, $e);
1386
+            }
1387
+        }
1388
+
1389
+        // restore original permissions
1390
+        chmod($testDir, 0777);
1391
+        clearstatcache(true, $testDir);
1392
+
1393
+        if ($couldRead) {
1394
+            $this->markTestSkipped('could read test files while test requires unreadable');
1395
+        }
1396
+    }
1397
+
1398
+    public function testIgnoredAccessDeniedException()
1399
+    {
1400
+        if ('\\' === \DIRECTORY_SEPARATOR) {
1401
+            $this->markTestSkipped('chmod is not supported on Windows');
1402
+        }
1403
+
1404
+        $finder = $this->buildFinder();
1405
+        $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
1406
+
1407
+        // make 'foo' directory non-readable
1408
+        $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
1409
+        chmod($testDir, 0333);
1410
+
1411
+        if (false === ($couldRead = is_readable($testDir))) {
1412
+            $this->assertIterator($this->toAbsolute([
1413
+                'foo bar',
1414
+                'test.php',
1415
+                'test.py',
1416
+                'qux/baz_100_1.py',
1417
+                'qux/baz_1_2.py',
1418
+                'qux_0_1.php',
1419
+                'qux_1000_1.php',
1420
+                'qux_1002_0.php',
1421
+                'qux_10_2.php',
1422
+                'qux_12_0.php',
1423
+                'qux_2_0.php',
1424
+                ]
1425
+            ), $finder->getIterator());
1426
+        }
1427
+
1428
+        // restore original permissions
1429
+        chmod($testDir, 0777);
1430
+        clearstatcache(true, $testDir);
1431
+
1432
+        if ($couldRead) {
1433
+            $this->markTestSkipped('could read test files while test requires unreadable');
1434
+        }
1435
+    }
1436
+
1437
+    /**
1438
+     * @group legacy
1439
+     * @expectedDeprecation The "Symfony\Component\Finder\Finder::sortByName()" method will have a new "bool $useNaturalSort = false" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
1440
+     */
1441
+    public function testInheritedClassCallSortByNameWithNoArguments()
1442
+    {
1443
+        $finderChild = new ClassThatInheritFinder();
1444
+        $finderChild->sortByName();
1445
+    }
1446
+
1447
+    protected function buildFinder()
1448
+    {
1449
+        return Finder::create();
1450
+    }
1451
+}
1452
+
1453
+class ClassThatInheritFinder extends Finder
1454
+{
1455
+    public function sortByName()
1456
+    {
1457
+        parent::sortByName();
1458
+    }
1459
+}