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