FinderTest.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Finder\Tests;
  11. use Symfony\Component\Finder\Finder;
  12. class FinderTest extends Iterator\RealIteratorTestCase
  13. {
  14. public function testCreate()
  15. {
  16. $this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
  17. }
  18. public function testDirectories()
  19. {
  20. $finder = $this->buildFinder();
  21. $this->assertSame($finder, $finder->directories());
  22. $this->assertIterator($this->toAbsolute(array('foo', 'qux', 'toto')), $finder->in(self::$tmpDir)->getIterator());
  23. $finder = $this->buildFinder();
  24. $finder->directories();
  25. $finder->files();
  26. $finder->directories();
  27. $this->assertIterator($this->toAbsolute(array('foo', 'qux', 'toto')), $finder->in(self::$tmpDir)->getIterator());
  28. }
  29. public function testFiles()
  30. {
  31. $finder = $this->buildFinder();
  32. $this->assertSame($finder, $finder->files());
  33. $this->assertIterator($this->toAbsolute(array('foo/bar.tmp',
  34. 'test.php',
  35. 'test.py',
  36. 'foo bar',
  37. 'qux/baz_100_1.py',
  38. 'qux/baz_1_2.py',
  39. 'qux_0_1.php',
  40. 'qux_1000_1.php',
  41. 'qux_1002_0.php',
  42. 'qux_10_2.php',
  43. 'qux_12_0.php',
  44. 'qux_2_0.php',
  45. )), $finder->in(self::$tmpDir)->getIterator());
  46. $finder = $this->buildFinder();
  47. $finder->files();
  48. $finder->directories();
  49. $finder->files();
  50. $this->assertIterator($this->toAbsolute(array('foo/bar.tmp',
  51. 'test.php',
  52. 'test.py',
  53. 'foo bar',
  54. 'qux/baz_100_1.py',
  55. 'qux/baz_1_2.py',
  56. 'qux_0_1.php',
  57. 'qux_1000_1.php',
  58. 'qux_1002_0.php',
  59. 'qux_10_2.php',
  60. 'qux_12_0.php',
  61. 'qux_2_0.php',
  62. )), $finder->in(self::$tmpDir)->getIterator());
  63. }
  64. public function testRemoveTrailingSlash()
  65. {
  66. $finder = $this->buildFinder();
  67. $expected = $this->toAbsolute(array(
  68. 'foo/bar.tmp',
  69. 'test.php',
  70. 'test.py',
  71. 'foo bar',
  72. 'qux/baz_100_1.py',
  73. 'qux/baz_1_2.py',
  74. 'qux_0_1.php',
  75. 'qux_1000_1.php',
  76. 'qux_1002_0.php',
  77. 'qux_10_2.php',
  78. 'qux_12_0.php',
  79. 'qux_2_0.php',
  80. ));
  81. $in = self::$tmpDir.'//';
  82. $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
  83. }
  84. public function testSymlinksNotResolved()
  85. {
  86. if ('\\' === \DIRECTORY_SEPARATOR) {
  87. $this->markTestSkipped('symlinks are not supported on Windows');
  88. }
  89. $finder = $this->buildFinder();
  90. symlink($this->toAbsolute('foo'), $this->toAbsolute('baz'));
  91. $expected = $this->toAbsolute(array('baz/bar.tmp'));
  92. $in = self::$tmpDir.'/baz/';
  93. try {
  94. $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
  95. unlink($this->toAbsolute('baz'));
  96. } catch (\Exception $e) {
  97. unlink($this->toAbsolute('baz'));
  98. throw $e;
  99. }
  100. }
  101. public function testBackPathNotNormalized()
  102. {
  103. $finder = $this->buildFinder();
  104. $expected = $this->toAbsolute(array('foo/../foo/bar.tmp'));
  105. $in = self::$tmpDir.'/foo/../foo/';
  106. $this->assertIterator($expected, $finder->in($in)->files()->getIterator());
  107. }
  108. public function testDepth()
  109. {
  110. $finder = $this->buildFinder();
  111. $this->assertSame($finder, $finder->depth('< 1'));
  112. $this->assertIterator($this->toAbsolute(array('foo',
  113. 'test.php',
  114. 'test.py',
  115. 'toto',
  116. 'foo bar',
  117. 'qux',
  118. 'qux_0_1.php',
  119. 'qux_1000_1.php',
  120. 'qux_1002_0.php',
  121. 'qux_10_2.php',
  122. 'qux_12_0.php',
  123. 'qux_2_0.php',
  124. )), $finder->in(self::$tmpDir)->getIterator());
  125. $finder = $this->buildFinder();
  126. $this->assertSame($finder, $finder->depth('<= 0'));
  127. $this->assertIterator($this->toAbsolute(array('foo',
  128. 'test.php',
  129. 'test.py',
  130. 'toto',
  131. 'foo bar',
  132. 'qux',
  133. 'qux_0_1.php',
  134. 'qux_1000_1.php',
  135. 'qux_1002_0.php',
  136. 'qux_10_2.php',
  137. 'qux_12_0.php',
  138. 'qux_2_0.php',
  139. )), $finder->in(self::$tmpDir)->getIterator());
  140. $finder = $this->buildFinder();
  141. $this->assertSame($finder, $finder->depth('>= 1'));
  142. $this->assertIterator($this->toAbsolute(array(
  143. 'foo/bar.tmp',
  144. 'qux/baz_100_1.py',
  145. 'qux/baz_1_2.py',
  146. )), $finder->in(self::$tmpDir)->getIterator());
  147. $finder = $this->buildFinder();
  148. $finder->depth('< 1')->depth('>= 1');
  149. $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
  150. }
  151. public function testDepthWithArrayParam()
  152. {
  153. $finder = $this->buildFinder();
  154. $finder->depth(array('>= 1', '< 2'));
  155. $this->assertIterator($this->toAbsolute(array(
  156. 'foo/bar.tmp',
  157. 'qux/baz_100_1.py',
  158. 'qux/baz_1_2.py',
  159. )), $finder->in(self::$tmpDir)->getIterator());
  160. }
  161. public function testName()
  162. {
  163. $finder = $this->buildFinder();
  164. $this->assertSame($finder, $finder->name('*.php'));
  165. $this->assertIterator($this->toAbsolute(array(
  166. 'test.php',
  167. 'qux_0_1.php',
  168. 'qux_1000_1.php',
  169. 'qux_1002_0.php',
  170. 'qux_10_2.php',
  171. 'qux_12_0.php',
  172. 'qux_2_0.php',
  173. )), $finder->in(self::$tmpDir)->getIterator());
  174. $finder = $this->buildFinder();
  175. $finder->name('test.ph*');
  176. $finder->name('test.py');
  177. $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
  178. $finder = $this->buildFinder();
  179. $finder->name('~^test~i');
  180. $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
  181. $finder = $this->buildFinder();
  182. $finder->name('~\\.php$~i');
  183. $this->assertIterator($this->toAbsolute(array(
  184. 'test.php',
  185. 'qux_0_1.php',
  186. 'qux_1000_1.php',
  187. 'qux_1002_0.php',
  188. 'qux_10_2.php',
  189. 'qux_12_0.php',
  190. 'qux_2_0.php',
  191. )), $finder->in(self::$tmpDir)->getIterator());
  192. $finder = $this->buildFinder();
  193. $finder->name('test.p{hp,y}');
  194. $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
  195. }
  196. public function testNameWithArrayParam()
  197. {
  198. $finder = $this->buildFinder();
  199. $finder->name(array('test.php', 'test.py'));
  200. $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
  201. }
  202. public function testNotName()
  203. {
  204. $finder = $this->buildFinder();
  205. $this->assertSame($finder, $finder->notName('*.php'));
  206. $this->assertIterator($this->toAbsolute(array(
  207. 'foo',
  208. 'foo/bar.tmp',
  209. 'test.py',
  210. 'toto',
  211. 'foo bar',
  212. 'qux',
  213. 'qux/baz_100_1.py',
  214. 'qux/baz_1_2.py',
  215. )), $finder->in(self::$tmpDir)->getIterator());
  216. $finder = $this->buildFinder();
  217. $finder->notName('*.php');
  218. $finder->notName('*.py');
  219. $this->assertIterator($this->toAbsolute(array(
  220. 'foo',
  221. 'foo/bar.tmp',
  222. 'toto',
  223. 'foo bar',
  224. 'qux',
  225. )), $finder->in(self::$tmpDir)->getIterator());
  226. $finder = $this->buildFinder();
  227. $finder->name('test.ph*');
  228. $finder->name('test.py');
  229. $finder->notName('*.php');
  230. $finder->notName('*.py');
  231. $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
  232. $finder = $this->buildFinder();
  233. $finder->name('test.ph*');
  234. $finder->name('test.py');
  235. $finder->notName('*.p{hp,y}');
  236. $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
  237. }
  238. public function testNotNameWithArrayParam()
  239. {
  240. $finder = $this->buildFinder();
  241. $finder->notName(array('*.php', '*.py'));
  242. $this->assertIterator($this->toAbsolute(array(
  243. 'foo',
  244. 'foo/bar.tmp',
  245. 'toto',
  246. 'foo bar',
  247. 'qux',
  248. )), $finder->in(self::$tmpDir)->getIterator());
  249. }
  250. /**
  251. * @dataProvider getRegexNameTestData
  252. */
  253. public function testRegexName($regex)
  254. {
  255. $finder = $this->buildFinder();
  256. $finder->name($regex);
  257. $this->assertIterator($this->toAbsolute(array(
  258. 'test.py',
  259. 'test.php',
  260. )), $finder->in(self::$tmpDir)->getIterator());
  261. }
  262. public function testSize()
  263. {
  264. $finder = $this->buildFinder();
  265. $this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
  266. $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
  267. }
  268. public function testSizeWithArrayParam()
  269. {
  270. $finder = $this->buildFinder();
  271. $this->assertSame($finder, $finder->files()->size(array('< 1K', '> 500')));
  272. $this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
  273. }
  274. public function testDate()
  275. {
  276. $finder = $this->buildFinder();
  277. $this->assertSame($finder, $finder->files()->date('until last month'));
  278. $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
  279. }
  280. public function testDateWithArrayParam()
  281. {
  282. $finder = $this->buildFinder();
  283. $this->assertSame($finder, $finder->files()->date(array('>= 2005-10-15', 'until last month')));
  284. $this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
  285. }
  286. public function testExclude()
  287. {
  288. $finder = $this->buildFinder();
  289. $this->assertSame($finder, $finder->exclude('foo'));
  290. $this->assertIterator($this->toAbsolute(array(
  291. 'test.php',
  292. 'test.py',
  293. 'toto',
  294. 'foo bar',
  295. 'qux',
  296. 'qux/baz_100_1.py',
  297. 'qux/baz_1_2.py',
  298. 'qux_0_1.php',
  299. 'qux_1000_1.php',
  300. 'qux_1002_0.php',
  301. 'qux_10_2.php',
  302. 'qux_12_0.php',
  303. 'qux_2_0.php',
  304. )), $finder->in(self::$tmpDir)->getIterator());
  305. }
  306. public function testIgnoreVCS()
  307. {
  308. $finder = $this->buildFinder();
  309. $this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
  310. $this->assertIterator($this->toAbsolute(array(
  311. '.git',
  312. 'foo',
  313. 'foo/bar.tmp',
  314. 'test.php',
  315. 'test.py',
  316. 'toto',
  317. 'toto/.git',
  318. '.bar',
  319. '.foo',
  320. '.foo/.bar',
  321. '.foo/bar',
  322. 'foo bar',
  323. 'qux',
  324. 'qux/baz_100_1.py',
  325. 'qux/baz_1_2.py',
  326. 'qux_0_1.php',
  327. 'qux_1000_1.php',
  328. 'qux_1002_0.php',
  329. 'qux_10_2.php',
  330. 'qux_12_0.php',
  331. 'qux_2_0.php',
  332. )), $finder->in(self::$tmpDir)->getIterator());
  333. $finder = $this->buildFinder();
  334. $finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
  335. $this->assertIterator($this->toAbsolute(array(
  336. '.git',
  337. 'foo',
  338. 'foo/bar.tmp',
  339. 'test.php',
  340. 'test.py',
  341. 'toto',
  342. 'toto/.git',
  343. '.bar',
  344. '.foo',
  345. '.foo/.bar',
  346. '.foo/bar',
  347. 'foo bar',
  348. 'qux',
  349. 'qux/baz_100_1.py',
  350. 'qux/baz_1_2.py',
  351. 'qux_0_1.php',
  352. 'qux_1000_1.php',
  353. 'qux_1002_0.php',
  354. 'qux_10_2.php',
  355. 'qux_12_0.php',
  356. 'qux_2_0.php',
  357. )), $finder->in(self::$tmpDir)->getIterator());
  358. $finder = $this->buildFinder();
  359. $this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
  360. $this->assertIterator($this->toAbsolute(array(
  361. 'foo',
  362. 'foo/bar.tmp',
  363. 'test.php',
  364. 'test.py',
  365. 'toto',
  366. '.bar',
  367. '.foo',
  368. '.foo/.bar',
  369. '.foo/bar',
  370. 'foo bar',
  371. 'qux',
  372. 'qux/baz_100_1.py',
  373. 'qux/baz_1_2.py',
  374. 'qux_0_1.php',
  375. 'qux_1000_1.php',
  376. 'qux_1002_0.php',
  377. 'qux_10_2.php',
  378. 'qux_12_0.php',
  379. 'qux_2_0.php',
  380. )), $finder->in(self::$tmpDir)->getIterator());
  381. }
  382. public function testIgnoreDotFiles()
  383. {
  384. $finder = $this->buildFinder();
  385. $this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
  386. $this->assertIterator($this->toAbsolute(array(
  387. '.git',
  388. '.bar',
  389. '.foo',
  390. '.foo/.bar',
  391. '.foo/bar',
  392. 'foo',
  393. 'foo/bar.tmp',
  394. 'test.php',
  395. 'test.py',
  396. 'toto',
  397. 'toto/.git',
  398. 'foo bar',
  399. 'qux',
  400. 'qux/baz_100_1.py',
  401. 'qux/baz_1_2.py',
  402. 'qux_0_1.php',
  403. 'qux_1000_1.php',
  404. 'qux_1002_0.php',
  405. 'qux_10_2.php',
  406. 'qux_12_0.php',
  407. 'qux_2_0.php',
  408. )), $finder->in(self::$tmpDir)->getIterator());
  409. $finder = $this->buildFinder();
  410. $finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
  411. $this->assertIterator($this->toAbsolute(array(
  412. '.git',
  413. '.bar',
  414. '.foo',
  415. '.foo/.bar',
  416. '.foo/bar',
  417. 'foo',
  418. 'foo/bar.tmp',
  419. 'test.php',
  420. 'test.py',
  421. 'toto',
  422. 'toto/.git',
  423. 'foo bar',
  424. 'qux',
  425. 'qux/baz_100_1.py',
  426. 'qux/baz_1_2.py',
  427. 'qux_0_1.php',
  428. 'qux_1000_1.php',
  429. 'qux_1002_0.php',
  430. 'qux_10_2.php',
  431. 'qux_12_0.php',
  432. 'qux_2_0.php',
  433. )), $finder->in(self::$tmpDir)->getIterator());
  434. $finder = $this->buildFinder();
  435. $this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
  436. $this->assertIterator($this->toAbsolute(array(
  437. 'foo',
  438. 'foo/bar.tmp',
  439. 'test.php',
  440. 'test.py',
  441. 'toto',
  442. 'foo bar',
  443. 'qux',
  444. 'qux/baz_100_1.py',
  445. 'qux/baz_1_2.py',
  446. 'qux_0_1.php',
  447. 'qux_1000_1.php',
  448. 'qux_1002_0.php',
  449. 'qux_10_2.php',
  450. 'qux_12_0.php',
  451. 'qux_2_0.php',
  452. )), $finder->in(self::$tmpDir)->getIterator());
  453. }
  454. public function testSortByName()
  455. {
  456. $finder = $this->buildFinder();
  457. $this->assertSame($finder, $finder->sortByName());
  458. $this->assertIterator($this->toAbsolute(array(
  459. 'foo',
  460. 'foo bar',
  461. 'foo/bar.tmp',
  462. 'qux',
  463. 'qux/baz_100_1.py',
  464. 'qux/baz_1_2.py',
  465. 'qux_0_1.php',
  466. 'qux_1000_1.php',
  467. 'qux_1002_0.php',
  468. 'qux_10_2.php',
  469. 'qux_12_0.php',
  470. 'qux_2_0.php',
  471. 'test.php',
  472. 'test.py',
  473. 'toto',
  474. )), $finder->in(self::$tmpDir)->getIterator());
  475. }
  476. public function testSortByType()
  477. {
  478. $finder = $this->buildFinder();
  479. $this->assertSame($finder, $finder->sortByType());
  480. $this->assertIterator($this->toAbsolute(array(
  481. 'foo',
  482. 'foo bar',
  483. 'toto',
  484. 'foo/bar.tmp',
  485. 'test.php',
  486. 'test.py',
  487. 'qux',
  488. 'qux/baz_100_1.py',
  489. 'qux/baz_1_2.py',
  490. 'qux_0_1.php',
  491. 'qux_1000_1.php',
  492. 'qux_1002_0.php',
  493. 'qux_10_2.php',
  494. 'qux_12_0.php',
  495. 'qux_2_0.php',
  496. )), $finder->in(self::$tmpDir)->getIterator());
  497. }
  498. public function testSortByAccessedTime()
  499. {
  500. $finder = $this->buildFinder();
  501. $this->assertSame($finder, $finder->sortByAccessedTime());
  502. $this->assertIterator($this->toAbsolute(array(
  503. 'foo/bar.tmp',
  504. 'test.php',
  505. 'toto',
  506. 'test.py',
  507. 'foo',
  508. 'foo bar',
  509. 'qux',
  510. 'qux/baz_100_1.py',
  511. 'qux/baz_1_2.py',
  512. 'qux_0_1.php',
  513. 'qux_1000_1.php',
  514. 'qux_1002_0.php',
  515. 'qux_10_2.php',
  516. 'qux_12_0.php',
  517. 'qux_2_0.php',
  518. )), $finder->in(self::$tmpDir)->getIterator());
  519. }
  520. public function testSortByChangedTime()
  521. {
  522. $finder = $this->buildFinder();
  523. $this->assertSame($finder, $finder->sortByChangedTime());
  524. $this->assertIterator($this->toAbsolute(array(
  525. 'toto',
  526. 'test.py',
  527. 'test.php',
  528. 'foo/bar.tmp',
  529. 'foo',
  530. 'foo bar',
  531. 'qux',
  532. 'qux/baz_100_1.py',
  533. 'qux/baz_1_2.py',
  534. 'qux_0_1.php',
  535. 'qux_1000_1.php',
  536. 'qux_1002_0.php',
  537. 'qux_10_2.php',
  538. 'qux_12_0.php',
  539. 'qux_2_0.php',
  540. )), $finder->in(self::$tmpDir)->getIterator());
  541. }
  542. public function testSortByModifiedTime()
  543. {
  544. $finder = $this->buildFinder();
  545. $this->assertSame($finder, $finder->sortByModifiedTime());
  546. $this->assertIterator($this->toAbsolute(array(
  547. 'foo/bar.tmp',
  548. 'test.php',
  549. 'toto',
  550. 'test.py',
  551. 'foo',
  552. 'foo bar',
  553. 'qux',
  554. 'qux/baz_100_1.py',
  555. 'qux/baz_1_2.py',
  556. 'qux_0_1.php',
  557. 'qux_1000_1.php',
  558. 'qux_1002_0.php',
  559. 'qux_10_2.php',
  560. 'qux_12_0.php',
  561. 'qux_2_0.php',
  562. )), $finder->in(self::$tmpDir)->getIterator());
  563. }
  564. public function testSortByNameNatural()
  565. {
  566. $finder = $this->buildFinder();
  567. $this->assertSame($finder, $finder->sortByName(true));
  568. $this->assertIterator($this->toAbsolute(array(
  569. 'foo',
  570. 'foo bar',
  571. 'foo/bar.tmp',
  572. 'qux',
  573. 'qux/baz_100_1.py',
  574. 'qux/baz_1_2.py',
  575. 'qux_0_1.php',
  576. 'qux_1000_1.php',
  577. 'qux_1002_0.php',
  578. 'qux_10_2.php',
  579. 'qux_12_0.php',
  580. 'qux_2_0.php',
  581. 'test.php',
  582. 'test.py',
  583. 'toto',
  584. )), $finder->in(self::$tmpDir)->getIterator());
  585. $finder = $this->buildFinder();
  586. $this->assertSame($finder, $finder->sortByName(false));
  587. $this->assertIterator($this->toAbsolute(array(
  588. 'foo',
  589. 'foo bar',
  590. 'foo/bar.tmp',
  591. 'qux',
  592. 'qux/baz_100_1.py',
  593. 'qux/baz_1_2.py',
  594. 'qux_0_1.php',
  595. 'qux_1000_1.php',
  596. 'qux_1002_0.php',
  597. 'qux_10_2.php',
  598. 'qux_12_0.php',
  599. 'qux_2_0.php',
  600. 'test.php',
  601. 'test.py',
  602. 'toto',
  603. )), $finder->in(self::$tmpDir)->getIterator());
  604. }
  605. public function testSort()
  606. {
  607. $finder = $this->buildFinder();
  608. $this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
  609. $this->assertIterator($this->toAbsolute(array(
  610. 'foo',
  611. 'foo bar',
  612. 'foo/bar.tmp',
  613. 'test.php',
  614. 'test.py',
  615. 'toto',
  616. 'qux',
  617. 'qux/baz_100_1.py',
  618. 'qux/baz_1_2.py',
  619. 'qux_0_1.php',
  620. 'qux_1000_1.php',
  621. 'qux_1002_0.php',
  622. 'qux_10_2.php',
  623. 'qux_12_0.php',
  624. 'qux_2_0.php',
  625. )), $finder->in(self::$tmpDir)->getIterator());
  626. }
  627. public function testFilter()
  628. {
  629. $finder = $this->buildFinder();
  630. $this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
  631. $this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
  632. }
  633. public function testFollowLinks()
  634. {
  635. if ('\\' == \DIRECTORY_SEPARATOR) {
  636. $this->markTestSkipped('symlinks are not supported on Windows');
  637. }
  638. $finder = $this->buildFinder();
  639. $this->assertSame($finder, $finder->followLinks());
  640. $this->assertIterator($this->toAbsolute(array(
  641. 'foo',
  642. 'foo/bar.tmp',
  643. 'test.php',
  644. 'test.py',
  645. 'toto',
  646. 'foo bar',
  647. 'qux',
  648. 'qux/baz_100_1.py',
  649. 'qux/baz_1_2.py',
  650. 'qux_0_1.php',
  651. 'qux_1000_1.php',
  652. 'qux_1002_0.php',
  653. 'qux_10_2.php',
  654. 'qux_12_0.php',
  655. 'qux_2_0.php',
  656. )), $finder->in(self::$tmpDir)->getIterator());
  657. }
  658. public function testIn()
  659. {
  660. $finder = $this->buildFinder();
  661. $iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
  662. $expected = array(
  663. self::$tmpDir.\DIRECTORY_SEPARATOR.'test.php',
  664. __DIR__.\DIRECTORY_SEPARATOR.'FinderTest.php',
  665. __DIR__.\DIRECTORY_SEPARATOR.'GlobTest.php',
  666. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_0_1.php',
  667. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1000_1.php',
  668. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_1002_0.php',
  669. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_10_2.php',
  670. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_12_0.php',
  671. self::$tmpDir.\DIRECTORY_SEPARATOR.'qux_2_0.php',
  672. );
  673. $this->assertIterator($expected, $iterator);
  674. }
  675. /**
  676. * @expectedException \InvalidArgumentException
  677. */
  678. public function testInWithNonExistentDirectory()
  679. {
  680. $finder = new Finder();
  681. $finder->in('foobar');
  682. }
  683. public function testInWithGlob()
  684. {
  685. $finder = $this->buildFinder();
  686. $finder->in(array(__DIR__.'/Fixtures/*/B/C/', __DIR__.'/Fixtures/*/*/B/C/'))->getIterator();
  687. $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
  688. }
  689. /**
  690. * @expectedException \InvalidArgumentException
  691. */
  692. public function testInWithNonDirectoryGlob()
  693. {
  694. $finder = new Finder();
  695. $finder->in(__DIR__.'/Fixtures/A/a*');
  696. }
  697. public function testInWithGlobBrace()
  698. {
  699. $finder = $this->buildFinder();
  700. $finder->in(array(__DIR__.'/Fixtures/{A,copy/A}/B/C'))->getIterator();
  701. $this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
  702. }
  703. /**
  704. * @expectedException \LogicException
  705. */
  706. public function testGetIteratorWithoutIn()
  707. {
  708. $finder = Finder::create();
  709. $finder->getIterator();
  710. }
  711. public function testGetIterator()
  712. {
  713. $finder = $this->buildFinder();
  714. $dirs = array();
  715. foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
  716. $dirs[] = (string) $dir;
  717. }
  718. $expected = $this->toAbsolute(array('foo', 'qux', 'toto'));
  719. sort($dirs);
  720. sort($expected);
  721. $this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
  722. $finder = $this->buildFinder();
  723. $this->assertEquals(3, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
  724. $finder = $this->buildFinder();
  725. $a = iterator_to_array($finder->directories()->in(self::$tmpDir));
  726. $a = array_values(array_map('strval', $a));
  727. sort($a);
  728. $this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
  729. }
  730. public function testRelativePath()
  731. {
  732. $finder = $this->buildFinder()->in(self::$tmpDir);
  733. $paths = array();
  734. foreach ($finder as $file) {
  735. $paths[] = $file->getRelativePath();
  736. }
  737. $ref = array('', '', '', '', '', '', '', '', '', '', '', 'foo', 'qux', 'qux', '');
  738. sort($ref);
  739. sort($paths);
  740. $this->assertEquals($ref, $paths);
  741. }
  742. public function testRelativePathname()
  743. {
  744. $finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
  745. $paths = array();
  746. foreach ($finder as $file) {
  747. $paths[] = $file->getRelativePathname();
  748. }
  749. $ref = array(
  750. 'test.php',
  751. 'toto',
  752. 'test.py',
  753. 'foo',
  754. 'foo'.\DIRECTORY_SEPARATOR.'bar.tmp',
  755. 'foo bar',
  756. 'qux',
  757. 'qux'.\DIRECTORY_SEPARATOR.'baz_100_1.py',
  758. 'qux'.\DIRECTORY_SEPARATOR.'baz_1_2.py',
  759. 'qux_0_1.php',
  760. 'qux_1000_1.php',
  761. 'qux_1002_0.php',
  762. 'qux_10_2.php',
  763. 'qux_12_0.php',
  764. 'qux_2_0.php',
  765. );
  766. sort($paths);
  767. sort($ref);
  768. $this->assertEquals($ref, $paths);
  769. }
  770. public function testAppendWithAFinder()
  771. {
  772. $finder = $this->buildFinder();
  773. $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
  774. $finder1 = $this->buildFinder();
  775. $finder1->directories()->in(self::$tmpDir);
  776. $finder = $finder->append($finder1);
  777. $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'qux', 'toto')), $finder->getIterator());
  778. }
  779. public function testAppendWithAnArray()
  780. {
  781. $finder = $this->buildFinder();
  782. $finder->files()->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
  783. $finder->append($this->toAbsolute(array('foo', 'toto')));
  784. $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
  785. }
  786. public function testAppendReturnsAFinder()
  787. {
  788. $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append(array()));
  789. }
  790. public function testAppendDoesNotRequireIn()
  791. {
  792. $finder = $this->buildFinder();
  793. $finder->in(self::$tmpDir.\DIRECTORY_SEPARATOR.'foo');
  794. $finder1 = Finder::create()->append($finder);
  795. $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator());
  796. }
  797. public function testCountDirectories()
  798. {
  799. $directory = Finder::create()->directories()->in(self::$tmpDir);
  800. $i = 0;
  801. foreach ($directory as $dir) {
  802. ++$i;
  803. }
  804. $this->assertCount($i, $directory);
  805. }
  806. public function testCountFiles()
  807. {
  808. $files = Finder::create()->files()->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures');
  809. $i = 0;
  810. foreach ($files as $file) {
  811. ++$i;
  812. }
  813. $this->assertCount($i, $files);
  814. }
  815. /**
  816. * @expectedException \LogicException
  817. */
  818. public function testCountWithoutIn()
  819. {
  820. $finder = Finder::create()->files();
  821. count($finder);
  822. }
  823. public function testHasResults()
  824. {
  825. $finder = $this->buildFinder();
  826. $finder->in(__DIR__);
  827. $this->assertTrue($finder->hasResults());
  828. }
  829. public function testNoResults()
  830. {
  831. $finder = $this->buildFinder();
  832. $finder->in(__DIR__)->name('DoesNotExist');
  833. $this->assertFalse($finder->hasResults());
  834. }
  835. /**
  836. * @dataProvider getContainsTestData
  837. */
  838. public function testContains($matchPatterns, $noMatchPatterns, $expected)
  839. {
  840. $finder = $this->buildFinder();
  841. $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
  842. ->name('*.txt')->sortByName()
  843. ->contains($matchPatterns)
  844. ->notContains($noMatchPatterns);
  845. $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
  846. }
  847. public function testContainsOnDirectory()
  848. {
  849. $finder = $this->buildFinder();
  850. $finder->in(__DIR__)
  851. ->directories()
  852. ->name('Fixtures')
  853. ->contains('abc');
  854. $this->assertIterator(array(), $finder);
  855. }
  856. public function testNotContainsOnDirectory()
  857. {
  858. $finder = $this->buildFinder();
  859. $finder->in(__DIR__)
  860. ->directories()
  861. ->name('Fixtures')
  862. ->notContains('abc');
  863. $this->assertIterator(array(), $finder);
  864. }
  865. /**
  866. * Searching in multiple locations involves AppendIterator which does an unnecessary rewind which leaves FilterIterator
  867. * with inner FilesystemIterator in an invalid state.
  868. *
  869. * @see https://bugs.php.net/68557
  870. */
  871. public function testMultipleLocations()
  872. {
  873. $locations = array(
  874. self::$tmpDir.'/',
  875. self::$tmpDir.'/toto/',
  876. );
  877. // it is expected that there are test.py test.php in the tmpDir
  878. $finder = new Finder();
  879. $finder->in($locations)
  880. // the default flag IGNORE_DOT_FILES fixes the problem indirectly
  881. // so we set it to false for better isolation
  882. ->ignoreDotFiles(false)
  883. ->depth('< 1')->name('test.php');
  884. $this->assertCount(1, $finder);
  885. }
  886. /**
  887. * Searching in multiple locations with sub directories involves
  888. * AppendIterator which does an unnecessary rewind which leaves
  889. * FilterIterator with inner FilesystemIterator in an invalid state.
  890. *
  891. * @see https://bugs.php.net/68557
  892. */
  893. public function testMultipleLocationsWithSubDirectories()
  894. {
  895. $locations = array(
  896. __DIR__.'/Fixtures/one',
  897. self::$tmpDir.\DIRECTORY_SEPARATOR.'toto',
  898. );
  899. $finder = $this->buildFinder();
  900. $finder->in($locations)->depth('< 10')->name('*.neon');
  901. $expected = array(
  902. __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
  903. __DIR__.'/Fixtures/one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
  904. );
  905. $this->assertIterator($expected, $finder);
  906. $this->assertIteratorInForeach($expected, $finder);
  907. }
  908. /**
  909. * Iterator keys must be the file pathname.
  910. */
  911. public function testIteratorKeys()
  912. {
  913. $finder = $this->buildFinder()->in(self::$tmpDir);
  914. foreach ($finder as $key => $file) {
  915. $this->assertEquals($file->getPathname(), $key);
  916. }
  917. }
  918. public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
  919. {
  920. $finder = $this->buildFinder();
  921. $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
  922. ->path('/^dir/');
  923. $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');
  924. $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
  925. }
  926. public function getContainsTestData()
  927. {
  928. return array(
  929. array('', '', array()),
  930. array('foo', 'bar', array()),
  931. array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),
  932. array('lorem ipsum dolor sit amet', 'foobar', array('lorem.txt')),
  933. array('sit', 'bar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),
  934. array('dolor sit amet', '@^L@m', array('dolor.txt', 'ipsum.txt')),
  935. array('/^lorem ipsum dolor sit amet$/m', 'foobar', array('lorem.txt')),
  936. array('lorem', 'foobar', array('lorem.txt')),
  937. array('', 'lorem', array('dolor.txt', 'ipsum.txt')),
  938. array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')),
  939. array(array('lorem', 'dolor'), array(), array('lorem.txt', 'ipsum.txt', 'dolor.txt')),
  940. array('', array('lorem', 'ipsum'), array('dolor.txt')),
  941. );
  942. }
  943. public function getRegexNameTestData()
  944. {
  945. return array(
  946. array('~.*t\\.p.+~i'),
  947. array('~t.*s~i'),
  948. );
  949. }
  950. /**
  951. * @dataProvider getTestPathData
  952. */
  953. public function testPath($matchPatterns, $noMatchPatterns, array $expected)
  954. {
  955. $finder = $this->buildFinder();
  956. $finder->in(__DIR__.\DIRECTORY_SEPARATOR.'Fixtures')
  957. ->path($matchPatterns)
  958. ->notPath($noMatchPatterns);
  959. $this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
  960. }
  961. public function getTestPathData()
  962. {
  963. return array(
  964. array('', '', array()),
  965. array('/^A\/B\/C/', '/C$/',
  966. array('A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat'),
  967. ),
  968. array('/^A\/B/', 'foobar',
  969. array(
  970. 'A'.\DIRECTORY_SEPARATOR.'B',
  971. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  972. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
  973. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
  974. ),
  975. ),
  976. array('A/B/C', 'foobar',
  977. array(
  978. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  979. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
  980. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  981. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
  982. ),
  983. ),
  984. array('A/B', 'foobar',
  985. array(
  986. //dirs
  987. 'A'.\DIRECTORY_SEPARATOR.'B',
  988. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  989. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B',
  990. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  991. //files
  992. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
  993. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
  994. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat.copy',
  995. 'copy'.\DIRECTORY_SEPARATOR.'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat.copy',
  996. ),
  997. ),
  998. array('/^with space\//', 'foobar',
  999. array(
  1000. 'with space'.\DIRECTORY_SEPARATOR.'foo.txt',
  1001. ),
  1002. ),
  1003. array(
  1004. '/^A/',
  1005. array('a.dat', 'abc.dat'),
  1006. array(
  1007. 'A',
  1008. 'A'.\DIRECTORY_SEPARATOR.'B',
  1009. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  1010. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
  1011. ),
  1012. ),
  1013. array(
  1014. array('/^A/', 'one'),
  1015. 'foobar',
  1016. array(
  1017. 'A',
  1018. 'A'.\DIRECTORY_SEPARATOR.'B',
  1019. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C',
  1020. 'A'.\DIRECTORY_SEPARATOR.'a.dat',
  1021. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'ab.dat',
  1022. 'A'.\DIRECTORY_SEPARATOR.'B'.\DIRECTORY_SEPARATOR.'C'.\DIRECTORY_SEPARATOR.'abc.dat',
  1023. 'one',
  1024. 'one'.\DIRECTORY_SEPARATOR.'a',
  1025. 'one'.\DIRECTORY_SEPARATOR.'b',
  1026. 'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'c.neon',
  1027. 'one'.\DIRECTORY_SEPARATOR.'b'.\DIRECTORY_SEPARATOR.'d.neon',
  1028. ),
  1029. ),
  1030. );
  1031. }
  1032. public function testAccessDeniedException()
  1033. {
  1034. if ('\\' === \DIRECTORY_SEPARATOR) {
  1035. $this->markTestSkipped('chmod is not supported on Windows');
  1036. }
  1037. $finder = $this->buildFinder();
  1038. $finder->files()->in(self::$tmpDir);
  1039. // make 'foo' directory non-readable
  1040. $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
  1041. chmod($testDir, 0333);
  1042. if (false === $couldRead = is_readable($testDir)) {
  1043. try {
  1044. $this->assertIterator($this->toAbsolute(array('foo bar', 'test.php', 'test.py')), $finder->getIterator());
  1045. $this->fail('Finder should throw an exception when opening a non-readable directory.');
  1046. } catch (\Exception $e) {
  1047. $expectedExceptionClass = 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException';
  1048. if ($e instanceof \PHPUnit_Framework_ExpectationFailedException) {
  1049. $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
  1050. }
  1051. if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
  1052. $this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
  1053. }
  1054. $this->assertInstanceOf($expectedExceptionClass, $e);
  1055. }
  1056. }
  1057. // restore original permissions
  1058. chmod($testDir, 0777);
  1059. clearstatcache($testDir);
  1060. if ($couldRead) {
  1061. $this->markTestSkipped('could read test files while test requires unreadable');
  1062. }
  1063. }
  1064. public function testIgnoredAccessDeniedException()
  1065. {
  1066. if ('\\' === \DIRECTORY_SEPARATOR) {
  1067. $this->markTestSkipped('chmod is not supported on Windows');
  1068. }
  1069. $finder = $this->buildFinder();
  1070. $finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
  1071. // make 'foo' directory non-readable
  1072. $testDir = self::$tmpDir.\DIRECTORY_SEPARATOR.'foo';
  1073. chmod($testDir, 0333);
  1074. if (false === ($couldRead = is_readable($testDir))) {
  1075. $this->assertIterator($this->toAbsolute(array(
  1076. 'foo bar',
  1077. 'test.php',
  1078. 'test.py',
  1079. 'qux/baz_100_1.py',
  1080. 'qux/baz_1_2.py',
  1081. 'qux_0_1.php',
  1082. 'qux_1000_1.php',
  1083. 'qux_1002_0.php',
  1084. 'qux_10_2.php',
  1085. 'qux_12_0.php',
  1086. 'qux_2_0.php',
  1087. )
  1088. ), $finder->getIterator());
  1089. }
  1090. // restore original permissions
  1091. chmod($testDir, 0777);
  1092. clearstatcache($testDir);
  1093. if ($couldRead) {
  1094. $this->markTestSkipped('could read test files while test requires unreadable');
  1095. }
  1096. }
  1097. protected function buildFinder()
  1098. {
  1099. return Finder::create();
  1100. }
  1101. }