Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Finder\Tests;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\Finder\Finder;
|
Chris@0
|
15
|
Chris@0
|
16 class FinderTest extends Iterator\RealIteratorTestCase
|
Chris@0
|
17 {
|
Chris@0
|
18 public function testCreate()
|
Chris@0
|
19 {
|
Chris@0
|
20 $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
|
Chris@0
|
21 }
|
Chris@0
|
22
|
Chris@0
|
23 public function testDirectories()
|
Chris@0
|
24 {
|
Chris@0
|
25 $finder = $this->buildFinder();
|
Chris@0
|
26 $this->assertSame($finder, $finder->directories());
|
Chris@17
|
27 $this->assertIterator($this->toAbsolute(['foo', 'toto']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
28
|
Chris@0
|
29 $finder = $this->buildFinder();
|
Chris@0
|
30 $finder->directories();
|
Chris@0
|
31 $finder->files();
|
Chris@0
|
32 $finder->directories();
|
Chris@17
|
33 $this->assertIterator($this->toAbsolute(['foo', 'toto']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
34 }
|
Chris@0
|
35
|
Chris@0
|
36 public function testFiles()
|
Chris@0
|
37 {
|
Chris@0
|
38 $finder = $this->buildFinder();
|
Chris@0
|
39 $this->assertSame($finder, $finder->files());
|
Chris@17
|
40 $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
41
|
Chris@0
|
42 $finder = $this->buildFinder();
|
Chris@0
|
43 $finder->files();
|
Chris@0
|
44 $finder->directories();
|
Chris@0
|
45 $finder->files();
|
Chris@17
|
46 $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
47 }
|
Chris@0
|
48
|
Chris@13
|
49 public function testRemoveTrailingSlash()
|
Chris@13
|
50 {
|
Chris@13
|
51 $finder = $this->buildFinder();
|
Chris@13
|
52
|
Chris@17
|
53 $expected = $this->toAbsolute(['foo/bar.tmp', 'test.php', 'test.py', 'foo bar']);
|
Chris@13
|
54 $in = self::$tmpDir.'//';
|
Chris@13
|
55
|
Chris@13
|
56 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
|
Chris@13
|
57 }
|
Chris@13
|
58
|
Chris@13
|
59 public function testSymlinksNotResolved()
|
Chris@13
|
60 {
|
Chris@17
|
61 if ('\\' === \DIRECTORY_SEPARATOR) {
|
Chris@13
|
62 $this->markTestSkipped('symlinks are not supported on Windows');
|
Chris@13
|
63 }
|
Chris@13
|
64
|
Chris@13
|
65 $finder = $this->buildFinder();
|
Chris@13
|
66
|
Chris@13
|
67 symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
|
Chris@17
|
68 $expected = $this->toAbsolute(['baz/bar.tmp']);
|
Chris@13
|
69 $in = self::$tmpDir.'/baz/';
|
Chris@13
|
70 try {
|
Chris@13
|
71 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
|
Chris@13
|
72 unlink($this->toAbsolute('baz'));
|
Chris@13
|
73 } catch (\Exception $e) {
|
Chris@13
|
74 unlink($this->toAbsolute('baz'));
|
Chris@13
|
75 throw $e;
|
Chris@13
|
76 }
|
Chris@13
|
77 }
|
Chris@13
|
78
|
Chris@13
|
79 public function testBackPathNotNormalized()
|
Chris@13
|
80 {
|
Chris@13
|
81 $finder = $this->buildFinder();
|
Chris@13
|
82
|
Chris@17
|
83 $expected = $this->toAbsolute(['foo/../foo/bar.tmp']);
|
Chris@13
|
84 $in = self::$tmpDir.'/foo/../foo/';
|
Chris@13
|
85 $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
|
Chris@13
|
86 }
|
Chris@13
|
87
|
Chris@0
|
88 public function testDepth()
|
Chris@0
|
89 {
|
Chris@0
|
90 $finder = $this->buildFinder();
|
Chris@0
|
91 $this->assertSame($finder, $finder->depth('< 1'));
|
Chris@17
|
92 $this->assertIterator($this->toAbsolute(['foo', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
93
|
Chris@0
|
94 $finder = $this->buildFinder();
|
Chris@0
|
95 $this->assertSame($finder, $finder->depth('<= 0'));
|
Chris@17
|
96 $this->assertIterator($this->toAbsolute(['foo', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
97
|
Chris@0
|
98 $finder = $this->buildFinder();
|
Chris@0
|
99 $this->assertSame($finder, $finder->depth('>= 1'));
|
Chris@17
|
100 $this->assertIterator($this->toAbsolute(['foo/bar.tmp']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
101
|
Chris@0
|
102 $finder = $this->buildFinder();
|
Chris@0
|
103 $finder->depth('< 1')->depth('>= 1');
|
Chris@17
|
104 $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
105 }
|
Chris@0
|
106
|
Chris@0
|
107 public function testName()
|
Chris@0
|
108 {
|
Chris@0
|
109 $finder = $this->buildFinder();
|
Chris@0
|
110 $this->assertSame($finder, $finder->name('*.php'));
|
Chris@17
|
111 $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
112
|
Chris@0
|
113 $finder = $this->buildFinder();
|
Chris@0
|
114 $finder->name('test.ph*');
|
Chris@0
|
115 $finder->name('test.py');
|
Chris@17
|
116 $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
117
|
Chris@0
|
118 $finder = $this->buildFinder();
|
Chris@0
|
119 $finder->name('~^test~i');
|
Chris@17
|
120 $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
121
|
Chris@0
|
122 $finder = $this->buildFinder();
|
Chris@0
|
123 $finder->name('~\\.php$~i');
|
Chris@17
|
124 $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
125
|
Chris@0
|
126 $finder = $this->buildFinder();
|
Chris@0
|
127 $finder->name('test.p{hp,y}');
|
Chris@17
|
128 $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
129 }
|
Chris@0
|
130
|
Chris@0
|
131 public function testNotName()
|
Chris@0
|
132 {
|
Chris@0
|
133 $finder = $this->buildFinder();
|
Chris@0
|
134 $this->assertSame($finder, $finder->notName('*.php'));
|
Chris@17
|
135 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
136
|
Chris@0
|
137 $finder = $this->buildFinder();
|
Chris@0
|
138 $finder->notName('*.php');
|
Chris@0
|
139 $finder->notName('*.py');
|
Chris@17
|
140 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
141
|
Chris@0
|
142 $finder = $this->buildFinder();
|
Chris@0
|
143 $finder->name('test.ph*');
|
Chris@0
|
144 $finder->name('test.py');
|
Chris@0
|
145 $finder->notName('*.php');
|
Chris@0
|
146 $finder->notName('*.py');
|
Chris@17
|
147 $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
148
|
Chris@0
|
149 $finder = $this->buildFinder();
|
Chris@0
|
150 $finder->name('test.ph*');
|
Chris@0
|
151 $finder->name('test.py');
|
Chris@0
|
152 $finder->notName('*.p{hp,y}');
|
Chris@17
|
153 $this->assertIterator([], $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
154 }
|
Chris@0
|
155
|
Chris@0
|
156 /**
|
Chris@0
|
157 * @dataProvider getRegexNameTestData
|
Chris@0
|
158 */
|
Chris@0
|
159 public function testRegexName($regex)
|
Chris@0
|
160 {
|
Chris@0
|
161 $finder = $this->buildFinder();
|
Chris@0
|
162 $finder->name($regex);
|
Chris@17
|
163 $this->assertIterator($this->toAbsolute(['test.py', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
164 }
|
Chris@0
|
165
|
Chris@0
|
166 public function testSize()
|
Chris@0
|
167 {
|
Chris@0
|
168 $finder = $this->buildFinder();
|
Chris@0
|
169 $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
|
Chris@17
|
170 $this->assertIterator($this->toAbsolute(['test.php']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
171 }
|
Chris@0
|
172
|
Chris@0
|
173 public function testDate()
|
Chris@0
|
174 {
|
Chris@0
|
175 $finder = $this->buildFinder();
|
Chris@0
|
176 $this->assertSame($finder, $finder->files()->date('until last month'));
|
Chris@17
|
177 $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
178 }
|
Chris@0
|
179
|
Chris@0
|
180 public function testExclude()
|
Chris@0
|
181 {
|
Chris@0
|
182 $finder = $this->buildFinder();
|
Chris@0
|
183 $this->assertSame($finder, $finder->exclude('foo'));
|
Chris@17
|
184 $this->assertIterator($this->toAbsolute(['test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 public function testIgnoreVCS()
|
Chris@0
|
188 {
|
Chris@0
|
189 $finder = $this->buildFinder();
|
Chris@0
|
190 $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
|
Chris@17
|
191 $this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
192
|
Chris@0
|
193 $finder = $this->buildFinder();
|
Chris@0
|
194 $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
|
Chris@17
|
195 $this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
196
|
Chris@0
|
197 $finder = $this->buildFinder();
|
Chris@0
|
198 $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
|
Chris@17
|
199 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
200 }
|
Chris@0
|
201
|
Chris@18
|
202 public function testIgnoreVCSCanBeDisabledAfterFirstIteration()
|
Chris@18
|
203 {
|
Chris@18
|
204 $finder = $this->buildFinder();
|
Chris@18
|
205 $finder->in(self::$tmpDir);
|
Chris@18
|
206 $finder->ignoreDotFiles(false);
|
Chris@18
|
207
|
Chris@18
|
208 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
|
Chris@18
|
209
|
Chris@18
|
210 $finder->ignoreVCS(false);
|
Chris@18
|
211 $this->assertIterator($this->toAbsolute(['.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
|
Chris@18
|
212 }
|
Chris@18
|
213
|
Chris@0
|
214 public function testIgnoreDotFiles()
|
Chris@0
|
215 {
|
Chris@0
|
216 $finder = $this->buildFinder();
|
Chris@0
|
217 $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
|
Chris@17
|
218 $this->assertIterator($this->toAbsolute(['.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
219
|
Chris@0
|
220 $finder = $this->buildFinder();
|
Chris@0
|
221 $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
|
Chris@17
|
222 $this->assertIterator($this->toAbsolute(['.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
223
|
Chris@0
|
224 $finder = $this->buildFinder();
|
Chris@0
|
225 $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
|
Chris@17
|
226 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
227 }
|
Chris@0
|
228
|
Chris@18
|
229 public function testIgnoreDotFilesCanBeDisabledAfterFirstIteration()
|
Chris@18
|
230 {
|
Chris@18
|
231 $finder = $this->buildFinder();
|
Chris@18
|
232 $finder->in(self::$tmpDir);
|
Chris@18
|
233
|
Chris@18
|
234 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->getIterator());
|
Chris@18
|
235
|
Chris@18
|
236 $finder->ignoreDotFiles(false);
|
Chris@18
|
237 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar']), $finder->getIterator());
|
Chris@18
|
238 }
|
Chris@18
|
239
|
Chris@0
|
240 public function testSortByName()
|
Chris@0
|
241 {
|
Chris@0
|
242 $finder = $this->buildFinder();
|
Chris@0
|
243 $this->assertSame($finder, $finder->sortByName());
|
Chris@17
|
244 $this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
245 }
|
Chris@0
|
246
|
Chris@0
|
247 public function testSortByType()
|
Chris@0
|
248 {
|
Chris@0
|
249 $finder = $this->buildFinder();
|
Chris@0
|
250 $this->assertSame($finder, $finder->sortByType());
|
Chris@17
|
251 $this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
252 }
|
Chris@0
|
253
|
Chris@0
|
254 public function testSortByAccessedTime()
|
Chris@0
|
255 {
|
Chris@0
|
256 $finder = $this->buildFinder();
|
Chris@0
|
257 $this->assertSame($finder, $finder->sortByAccessedTime());
|
Chris@17
|
258 $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
259 }
|
Chris@0
|
260
|
Chris@0
|
261 public function testSortByChangedTime()
|
Chris@0
|
262 {
|
Chris@0
|
263 $finder = $this->buildFinder();
|
Chris@0
|
264 $this->assertSame($finder, $finder->sortByChangedTime());
|
Chris@17
|
265 $this->assertIterator($this->toAbsolute(['toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
266 }
|
Chris@0
|
267
|
Chris@0
|
268 public function testSortByModifiedTime()
|
Chris@0
|
269 {
|
Chris@0
|
270 $finder = $this->buildFinder();
|
Chris@0
|
271 $this->assertSame($finder, $finder->sortByModifiedTime());
|
Chris@17
|
272 $this->assertIterator($this->toAbsolute(['foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
273 }
|
Chris@0
|
274
|
Chris@0
|
275 public function testSort()
|
Chris@0
|
276 {
|
Chris@0
|
277 $finder = $this->buildFinder();
|
Chris@0
|
278 $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
|
Chris@17
|
279 $this->assertIterator($this->toAbsolute(['foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
280 }
|
Chris@0
|
281
|
Chris@0
|
282 public function testFilter()
|
Chris@0
|
283 {
|
Chris@0
|
284 $finder = $this->buildFinder();
|
Chris@0
|
285 $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
|
Chris@17
|
286 $this->assertIterator($this->toAbsolute(['test.php', 'test.py']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
287 }
|
Chris@0
|
288
|
Chris@0
|
289 public function testFollowLinks()
|
Chris@0
|
290 {
|
Chris@17
|
291 if ('\\' == \DIRECTORY_SEPARATOR) {
|
Chris@0
|
292 $this->markTestSkipped('symlinks are not supported on Windows');
|
Chris@0
|
293 }
|
Chris@0
|
294
|
Chris@0
|
295 $finder = $this->buildFinder();
|
Chris@0
|
296 $this->assertSame($finder, $finder->followLinks());
|
Chris@17
|
297 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar']), $finder->in(self::$tmpDir)->getIterator());
|
Chris@0
|
298 }
|
Chris@0
|
299
|
Chris@0
|
300 public function testIn()
|
Chris@0
|
301 {
|
Chris@0
|
302 $finder = $this->buildFinder();
|
Chris@17
|
303 $iterator = $finder->files()->name('*.php')->depth('< 1')->in([self::$tmpDir, __DIR__])->getIterator();
|
Chris@0
|
304
|
Chris@17
|
305 $expected = [
|
Chris@17
|
306 self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
|
Chris@17
|
307 __DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
|
Chris@17
|
308 __DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
|
Chris@17
|
309 ];
|
Chris@0
|
310
|
Chris@0
|
311 $this->assertIterator($expected, $iterator);
|
Chris@0
|
312 }
|
Chris@0
|
313
|
Chris@0
|
314 /**
|
Chris@0
|
315 * @expectedException \InvalidArgumentException
|
Chris@0
|
316 */
|
Chris@0
|
317 public function testInWithNonExistentDirectory()
|
Chris@0
|
318 {
|
Chris@0
|
319 $finder = new Finder();
|
Chris@0
|
320 $finder->in('foobar');
|
Chris@0
|
321 }
|
Chris@0
|
322
|
Chris@0
|
323 public function testInWithGlob()
|
Chris@0
|
324 {
|
Chris@0
|
325 $finder = $this->buildFinder();
|
Chris@17
|
326 $finder->in([__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'])->getIterator();
|
Chris@0
|
327
|
Chris@17
|
328 $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
|
Chris@0
|
329 }
|
Chris@0
|
330
|
Chris@0
|
331 /**
|
Chris@0
|
332 * @expectedException \InvalidArgumentException
|
Chris@0
|
333 */
|
Chris@0
|
334 public function testInWithNonDirectoryGlob()
|
Chris@0
|
335 {
|
Chris@0
|
336 $finder = new Finder();
|
Chris@0
|
337 $finder->in(__DIR__.'/Fixtures/A/a*');
|
Chris@0
|
338 }
|
Chris@0
|
339
|
Chris@0
|
340 public function testInWithGlobBrace()
|
Chris@0
|
341 {
|
Chris@18
|
342 if (!\defined('GLOB_BRACE')) {
|
Chris@18
|
343 $this->markTestSkipped('Glob brace is not supported on this system.');
|
Chris@18
|
344 }
|
Chris@18
|
345
|
Chris@0
|
346 $finder = $this->buildFinder();
|
Chris@17
|
347 $finder->in([__DIR__.'/Fixtures/{A,copy/A}/B/C'])->getIterator();
|
Chris@0
|
348
|
Chris@17
|
349 $this->assertIterator($this->toAbsoluteFixtures(['A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy']), $finder);
|
Chris@0
|
350 }
|
Chris@0
|
351
|
Chris@0
|
352 /**
|
Chris@0
|
353 * @expectedException \LogicException
|
Chris@0
|
354 */
|
Chris@0
|
355 public function testGetIteratorWithoutIn()
|
Chris@0
|
356 {
|
Chris@0
|
357 $finder = Finder::create();
|
Chris@0
|
358 $finder->getIterator();
|
Chris@0
|
359 }
|
Chris@0
|
360
|
Chris@0
|
361 public function testGetIterator()
|
Chris@0
|
362 {
|
Chris@0
|
363 $finder = $this->buildFinder();
|
Chris@17
|
364 $dirs = [];
|
Chris@0
|
365 foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
|
Chris@0
|
366 $dirs[] = (string) $dir;
|
Chris@0
|
367 }
|
Chris@0
|
368
|
Chris@17
|
369 $expected = $this->toAbsolute(['foo', 'toto']);
|
Chris@0
|
370
|
Chris@0
|
371 sort($dirs);
|
Chris@0
|
372 sort($expected);
|
Chris@0
|
373
|
Chris@0
|
374 $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
|
Chris@0
|
375
|
Chris@0
|
376 $finder = $this->buildFinder();
|
Chris@0
|
377 $this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
|
Chris@0
|
378
|
Chris@0
|
379 $finder = $this->buildFinder();
|
Chris@0
|
380 $a = iterator_to_array($finder->directories()->in(self::$tmpDir));
|
Chris@0
|
381 $a = array_values(array_map('strval', $a));
|
Chris@0
|
382 sort($a);
|
Chris@0
|
383 $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
|
Chris@0
|
384 }
|
Chris@0
|
385
|
Chris@0
|
386 public function testRelativePath()
|
Chris@0
|
387 {
|
Chris@0
|
388 $finder = $this->buildFinder()->in(self::$tmpDir);
|
Chris@0
|
389
|
Chris@17
|
390 $paths = [];
|
Chris@0
|
391
|
Chris@0
|
392 foreach ($finder as $file) {
|
Chris@0
|
393 $paths[] = $file->getRelativePath();
|
Chris@0
|
394 }
|
Chris@0
|
395
|
Chris@17
|
396 $ref = ['', '', '', '', 'foo', ''];
|
Chris@0
|
397
|
Chris@0
|
398 sort($ref);
|
Chris@0
|
399 sort($paths);
|
Chris@0
|
400
|
Chris@0
|
401 $this->assertEquals($ref, $paths);
|
Chris@0
|
402 }
|
Chris@0
|
403
|
Chris@0
|
404 public function testRelativePathname()
|
Chris@0
|
405 {
|
Chris@0
|
406 $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
|
Chris@0
|
407
|
Chris@17
|
408 $paths = [];
|
Chris@0
|
409
|
Chris@0
|
410 foreach ($finder as $file) {
|
Chris@0
|
411 $paths[] = $file->getRelativePathname();
|
Chris@0
|
412 }
|
Chris@0
|
413
|
Chris@17
|
414 $ref = ['test.php', 'toto', 'test.py', 'foo', 'foo'.\DIRECTORY_SEPARATOR.'bar.tmp', 'foo bar'];
|
Chris@0
|
415
|
Chris@0
|
416 sort($paths);
|
Chris@0
|
417 sort($ref);
|
Chris@0
|
418
|
Chris@0
|
419 $this->assertEquals($ref, $paths);
|
Chris@0
|
420 }
|
Chris@0
|
421
|
Chris@0
|
422 public function testAppendWithAFinder()
|
Chris@0
|
423 {
|
Chris@0
|
424 $finder = $this->buildFinder();
|
Chris@17
|
425 $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
|
Chris@0
|
426
|
Chris@0
|
427 $finder1 = $this->buildFinder();
|
Chris@0
|
428 $finder1->directories()->in(self::$tmpDir);
|
Chris@0
|
429
|
Chris@0
|
430 $finder = $finder->append($finder1);
|
Chris@0
|
431
|
Chris@17
|
432 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
|
Chris@0
|
433 }
|
Chris@0
|
434
|
Chris@0
|
435 public function testAppendWithAnArray()
|
Chris@0
|
436 {
|
Chris@0
|
437 $finder = $this->buildFinder();
|
Chris@17
|
438 $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
|
Chris@0
|
439
|
Chris@17
|
440 $finder->append($this->toAbsolute(['foo', 'toto']));
|
Chris@0
|
441
|
Chris@17
|
442 $this->assertIterator($this->toAbsolute(['foo', 'foo/bar.tmp', 'toto']), $finder->getIterator());
|
Chris@0
|
443 }
|
Chris@0
|
444
|
Chris@0
|
445 public function testAppendReturnsAFinder()
|
Chris@0
|
446 {
|
Chris@17
|
447 $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append([]));
|
Chris@0
|
448 }
|
Chris@0
|
449
|
Chris@0
|
450 public function testAppendDoesNotRequireIn()
|
Chris@0
|
451 {
|
Chris@0
|
452 $finder = $this->buildFinder();
|
Chris@17
|
453 $finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
|
Chris@0
|
454
|
Chris@0
|
455 $finder1 = Finder::create()->append($finder);
|
Chris@0
|
456
|
Chris@0
|
457 $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
|
Chris@0
|
458 }
|
Chris@0
|
459
|
Chris@0
|
460 public function testCountDirectories()
|
Chris@0
|
461 {
|
Chris@0
|
462 $directory = Finder::create()->directories()->in(self::$tmpDir);
|
Chris@0
|
463 $i = 0;
|
Chris@0
|
464
|
Chris@0
|
465 foreach ($directory as $dir) {
|
Chris@0
|
466 ++$i;
|
Chris@0
|
467 }
|
Chris@0
|
468
|
Chris@0
|
469 $this->assertCount($i, $directory);
|
Chris@0
|
470 }
|
Chris@0
|
471
|
Chris@0
|
472 public function testCountFiles()
|
Chris@0
|
473 {
|
Chris@17
|
474 $files = Finder::create()->files()->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
|
Chris@0
|
475 $i = 0;
|
Chris@0
|
476
|
Chris@0
|
477 foreach ($files as $file) {
|
Chris@0
|
478 ++$i;
|
Chris@0
|
479 }
|
Chris@0
|
480
|
Chris@0
|
481 $this->assertCount($i, $files);
|
Chris@0
|
482 }
|
Chris@0
|
483
|
Chris@0
|
484 /**
|
Chris@0
|
485 * @expectedException \LogicException
|
Chris@0
|
486 */
|
Chris@0
|
487 public function testCountWithoutIn()
|
Chris@0
|
488 {
|
Chris@0
|
489 $finder = Finder::create()->files();
|
Chris@17
|
490 \count($finder);
|
Chris@0
|
491 }
|
Chris@0
|
492
|
Chris@12
|
493 public function testHasResults()
|
Chris@12
|
494 {
|
Chris@12
|
495 $finder = $this->buildFinder();
|
Chris@12
|
496 $finder->in(__DIR__);
|
Chris@12
|
497 $this->assertTrue($finder->hasResults());
|
Chris@12
|
498 }
|
Chris@12
|
499
|
Chris@12
|
500 public function testNoResults()
|
Chris@12
|
501 {
|
Chris@12
|
502 $finder = $this->buildFinder();
|
Chris@12
|
503 $finder->in(__DIR__)->name('DoesNotExist');
|
Chris@12
|
504 $this->assertFalse($finder->hasResults());
|
Chris@12
|
505 }
|
Chris@12
|
506
|
Chris@0
|
507 /**
|
Chris@0
|
508 * @dataProvider getContainsTestData
|
Chris@0
|
509 */
|
Chris@0
|
510 public function testContains($matchPatterns, $noMatchPatterns, $expected)
|
Chris@0
|
511 {
|
Chris@0
|
512 $finder = $this->buildFinder();
|
Chris@17
|
513 $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
|
Chris@0
|
514 ->name('*.txt')->sortByName()
|
Chris@0
|
515 ->contains($matchPatterns)
|
Chris@0
|
516 ->notContains($noMatchPatterns);
|
Chris@0
|
517
|
Chris@0
|
518 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
|
Chris@0
|
519 }
|
Chris@0
|
520
|
Chris@0
|
521 public function testContainsOnDirectory()
|
Chris@0
|
522 {
|
Chris@0
|
523 $finder = $this->buildFinder();
|
Chris@0
|
524 $finder->in(__DIR__)
|
Chris@0
|
525 ->directories()
|
Chris@0
|
526 ->name('Fixtures')
|
Chris@0
|
527 ->contains('abc');
|
Chris@17
|
528 $this->assertIterator([], $finder);
|
Chris@0
|
529 }
|
Chris@0
|
530
|
Chris@0
|
531 public function testNotContainsOnDirectory()
|
Chris@0
|
532 {
|
Chris@0
|
533 $finder = $this->buildFinder();
|
Chris@0
|
534 $finder->in(__DIR__)
|
Chris@0
|
535 ->directories()
|
Chris@0
|
536 ->name('Fixtures')
|
Chris@0
|
537 ->notContains('abc');
|
Chris@17
|
538 $this->assertIterator([], $finder);
|
Chris@0
|
539 }
|
Chris@0
|
540
|
Chris@0
|
541 /**
|
Chris@0
|
542 * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
|
Chris@0
|
543 * with inner FilesystemIterator in an invalid state.
|
Chris@0
|
544 *
|
Chris@0
|
545 * @see https://bugs.php.net/68557
|
Chris@0
|
546 */
|
Chris@0
|
547 public function testMultipleLocations()
|
Chris@0
|
548 {
|
Chris@17
|
549 $locations = [
|
Chris@0
|
550 self::$tmpDir.'/',
|
Chris@0
|
551 self::$tmpDir.'/toto/',
|
Chris@17
|
552 ];
|
Chris@0
|
553
|
Chris@0
|
554 // it is expected that there are test.py test.php in the tmpDir
|
Chris@0
|
555 $finder = new Finder();
|
Chris@0
|
556 $finder->in($locations)
|
Chris@0
|
557 // the default flag IGNORE_DOT_FILES fixes the problem indirectly
|
Chris@0
|
558 // so we set it to false for better isolation
|
Chris@0
|
559 ->ignoreDotFiles(false)
|
Chris@0
|
560 ->depth('< 1')->name('test.php');
|
Chris@0
|
561
|
Chris@0
|
562 $this->assertCount(1, $finder);
|
Chris@0
|
563 }
|
Chris@0
|
564
|
Chris@0
|
565 /**
|
Chris@0
|
566 * Searching in multiple locations with sub directories involves
|
Chris@0
|
567 * AppendIterator which does an unnecessary rewind which leaves
|
Chris@0
|
568 * FilterIterator with inner FilesystemIterator in an invalid state.
|
Chris@0
|
569 *
|
Chris@0
|
570 * @see https://bugs.php.net/68557
|
Chris@0
|
571 */
|
Chris@0
|
572 public function testMultipleLocationsWithSubDirectories()
|
Chris@0
|
573 {
|
Chris@17
|
574 $locations = [
|
Chris@0
|
575 __DIR__.'/Fixtures/one',
|
Chris@17
|
576 self::$tmpDir.\DIRECTORY_SEPARATOR.'toto',
|
Chris@17
|
577 ];
|
Chris@0
|
578
|
Chris@0
|
579 $finder = $this->buildFinder();
|
Chris@0
|
580 $finder->in($locations)->depth('< 10')->name('*.neon');
|
Chris@0
|
581
|
Chris@17
|
582 $expected = [
|
Chris@17
|
583 __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
|
Chris@17
|
584 __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
|
Chris@17
|
585 ];
|
Chris@0
|
586
|
Chris@0
|
587 $this->assertIterator($expected, $finder);
|
Chris@0
|
588 $this->assertIteratorInForeach($expected, $finder);
|
Chris@0
|
589 }
|
Chris@0
|
590
|
Chris@0
|
591 /**
|
Chris@0
|
592 * Iterator keys must be the file pathname.
|
Chris@0
|
593 */
|
Chris@0
|
594 public function testIteratorKeys()
|
Chris@0
|
595 {
|
Chris@0
|
596 $finder = $this->buildFinder()->in(self::$tmpDir);
|
Chris@0
|
597 foreach ($finder as $key => $file) {
|
Chris@0
|
598 $this->assertEquals($file->getPathname(), $key);
|
Chris@0
|
599 }
|
Chris@0
|
600 }
|
Chris@0
|
601
|
Chris@0
|
602 public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
|
Chris@0
|
603 {
|
Chris@0
|
604 $finder = $this->buildFinder();
|
Chris@17
|
605 $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
|
Chris@0
|
606 ->path('/^dir/');
|
Chris@0
|
607
|
Chris@17
|
608 $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'];
|
Chris@0
|
609 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
|
Chris@0
|
610 }
|
Chris@0
|
611
|
Chris@0
|
612 public function getContainsTestData()
|
Chris@0
|
613 {
|
Chris@17
|
614 return [
|
Chris@17
|
615 ['', '', []],
|
Chris@17
|
616 ['foo', 'bar', []],
|
Chris@17
|
617 ['', 'foobar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
|
Chris@17
|
618 ['lorem ipsum dolor sit amet', 'foobar', ['lorem.txt']],
|
Chris@17
|
619 ['sit', 'bar', ['dolor.txt', 'ipsum.txt', 'lorem.txt']],
|
Chris@17
|
620 ['dolor sit amet', '@^L@m', ['dolor.txt', 'ipsum.txt']],
|
Chris@17
|
621 ['/^lorem ipsum dolor sit amet$/m', 'foobar', ['lorem.txt']],
|
Chris@17
|
622 ['lorem', 'foobar', ['lorem.txt']],
|
Chris@17
|
623 ['', 'lorem', ['dolor.txt', 'ipsum.txt']],
|
Chris@17
|
624 ['ipsum dolor sit amet', '/^IPSUM/m', ['lorem.txt']],
|
Chris@17
|
625 ];
|
Chris@0
|
626 }
|
Chris@0
|
627
|
Chris@0
|
628 public function getRegexNameTestData()
|
Chris@0
|
629 {
|
Chris@17
|
630 return [
|
Chris@17
|
631 ['~.+\\.p.+~i'],
|
Chris@17
|
632 ['~t.*s~i'],
|
Chris@17
|
633 ];
|
Chris@0
|
634 }
|
Chris@0
|
635
|
Chris@0
|
636 /**
|
Chris@0
|
637 * @dataProvider getTestPathData
|
Chris@0
|
638 */
|
Chris@0
|
639 public function testPath($matchPatterns, $noMatchPatterns, array $expected)
|
Chris@0
|
640 {
|
Chris@0
|
641 $finder = $this->buildFinder();
|
Chris@17
|
642 $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
|
Chris@0
|
643 ->path($matchPatterns)
|
Chris@0
|
644 ->notPath($noMatchPatterns);
|
Chris@0
|
645
|
Chris@0
|
646 $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
|
Chris@0
|
647 }
|
Chris@0
|
648
|
Chris@0
|
649 public function getTestPathData()
|
Chris@0
|
650 {
|
Chris@17
|
651 return [
|
Chris@17
|
652 ['', '', []],
|
Chris@17
|
653 ['/^A\/B\/C/', '/C$/',
|
Chris@17
|
654 ['A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat'],
|
Chris@17
|
655 ],
|
Chris@17
|
656 ['/^A\/B/', 'foobar',
|
Chris@17
|
657 [
|
Chris@17
|
658 'A'.\DIRECTORY_SEPARATOR.'B',
|
Chris@17
|
659 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
|
Chris@17
|
660 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
|
Chris@17
|
661 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
|
Chris@17
|
662 ],
|
Chris@17
|
663 ],
|
Chris@17
|
664 ['A/B/C', 'foobar',
|
Chris@17
|
665 [
|
Chris@17
|
666 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
|
Chris@17
|
667 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
|
Chris@17
|
668 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
|
Chris@17
|
669 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
|
Chris@17
|
670 ],
|
Chris@17
|
671 ],
|
Chris@17
|
672 ['A/B', 'foobar',
|
Chris@17
|
673 [
|
Chris@0
|
674 //dirs
|
Chris@17
|
675 'A'.\DIRECTORY_SEPARATOR.'B',
|
Chris@17
|
676 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
|
Chris@17
|
677 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B',
|
Chris@17
|
678 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
|
Chris@0
|
679 //files
|
Chris@17
|
680 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
|
Chris@17
|
681 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
|
Chris@17
|
682 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy',
|
Chris@17
|
683 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
|
Chris@17
|
684 ],
|
Chris@17
|
685 ],
|
Chris@17
|
686 ['/^with space\//', 'foobar',
|
Chris@17
|
687 [
|
Chris@17
|
688 'with space'.\DIRECTORY_SEPARATOR.'foo.txt',
|
Chris@17
|
689 ],
|
Chris@17
|
690 ],
|
Chris@17
|
691 ];
|
Chris@0
|
692 }
|
Chris@0
|
693
|
Chris@0
|
694 public function testAccessDeniedException()
|
Chris@0
|
695 {
|
Chris@17
|
696 if ('\\' === \DIRECTORY_SEPARATOR) {
|
Chris@0
|
697 $this->markTestSkipped('chmod is not supported on Windows');
|
Chris@0
|
698 }
|
Chris@0
|
699
|
Chris@0
|
700 $finder = $this->buildFinder();
|
Chris@0
|
701 $finder->files()->in(self::$tmpDir);
|
Chris@0
|
702
|
Chris@0
|
703 // make 'foo' directory non-readable
|
Chris@17
|
704 $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
|
Chris@0
|
705 chmod($testDir, 0333);
|
Chris@0
|
706
|
Chris@0
|
707 if (false === $couldRead = is_readable($testDir)) {
|
Chris@0
|
708 try {
|
Chris@17
|
709 $this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
|
Chris@0
|
710 $this->fail('Finder should throw an exception when opening a non-readable directory.');
|
Chris@0
|
711 } catch (\Exception $e) {
|
Chris@0
|
712 $expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
|
Chris@0
|
713 if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {
|
Chris@0
|
714 $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
|
Chris@0
|
715 }
|
Chris@0
|
716
|
Chris@0
|
717 if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
|
Chris@0
|
718 $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
|
Chris@0
|
719 }
|
Chris@0
|
720
|
Chris@0
|
721 $this->assertInstanceOf($expectedExceptionClass, $e);
|
Chris@0
|
722 }
|
Chris@0
|
723 }
|
Chris@0
|
724
|
Chris@0
|
725 // restore original permissions
|
Chris@0
|
726 chmod($testDir, 0777);
|
Chris@17
|
727 clearstatcache(true, $testDir);
|
Chris@0
|
728
|
Chris@0
|
729 if ($couldRead) {
|
Chris@0
|
730 $this->markTestSkipped('could read test files while test requires unreadable');
|
Chris@0
|
731 }
|
Chris@0
|
732 }
|
Chris@0
|
733
|
Chris@0
|
734 public function testIgnoredAccessDeniedException()
|
Chris@0
|
735 {
|
Chris@17
|
736 if ('\\' === \DIRECTORY_SEPARATOR) {
|
Chris@0
|
737 $this->markTestSkipped('chmod is not supported on Windows');
|
Chris@0
|
738 }
|
Chris@0
|
739
|
Chris@0
|
740 $finder = $this->buildFinder();
|
Chris@0
|
741 $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
|
Chris@0
|
742
|
Chris@0
|
743 // make 'foo' directory non-readable
|
Chris@17
|
744 $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
|
Chris@0
|
745 chmod($testDir, 0333);
|
Chris@0
|
746
|
Chris@0
|
747 if (false === ($couldRead = is_readable($testDir))) {
|
Chris@17
|
748 $this->assertIterator($this->toAbsolute(['foo bar', 'test.php', 'test.py']), $finder->getIterator());
|
Chris@0
|
749 }
|
Chris@0
|
750
|
Chris@0
|
751 // restore original permissions
|
Chris@0
|
752 chmod($testDir, 0777);
|
Chris@17
|
753 clearstatcache(true, $testDir);
|
Chris@0
|
754
|
Chris@0
|
755 if ($couldRead) {
|
Chris@0
|
756 $this->markTestSkipped('could read test files while test requires unreadable');
|
Chris@0
|
757 }
|
Chris@0
|
758 }
|
Chris@0
|
759
|
Chris@0
|
760 protected function buildFinder()
|
Chris@0
|
761 {
|
Chris@0
|
762 return Finder::create();
|
Chris@0
|
763 }
|
Chris@0
|
764 }
|