PageRenderTime 63ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/Group-I/jobeet/lib/vendor/symfony/test/unit/util/sfFinderTest.php

https://bitbucket.org/hosseinzolfi/db-lab-spring-2011/
PHP | 229 lines | 182 code | 31 blank | 16 comment | 0 complexity | 79c1499fa846a0f06ba80bab19063e22 MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once(dirname(__FILE__).'/../../bootstrap/unit.php');
  10. class my_lime_test extends lime_test
  11. {
  12. public function arrays_are_equal($a, $b, $message)
  13. {
  14. sort($a);
  15. sort($b);
  16. return $this->is($a, $b, $message);
  17. }
  18. }
  19. $t = new my_lime_test(39);
  20. require_once($_test_dir.'/../lib/util/sfFinder.class.php');
  21. $fixtureDir = dirname(__FILE__).'/fixtures/finder';
  22. $phpFiles = array(
  23. 'dir1/dir2/file21.php',
  24. 'dir1/file12.php',
  25. );
  26. $txtFiles = array(
  27. 'FILE5.txt',
  28. 'file2.txt',
  29. );
  30. $regexpFiles = array(
  31. 'dir1/dir2/file21.php',
  32. 'dir1/dir2/file22',
  33. 'dir1/dir2/file23',
  34. 'dir1/dir2/file24',
  35. 'file2.txt',
  36. );
  37. $regexpWithModifierFiles = array(
  38. 'dir1/dir2/file21.php',
  39. 'dir1/dir2/file22',
  40. 'dir1/dir2/file23',
  41. 'dir1/dir2/file24',
  42. 'FILE5.txt',
  43. 'file2.txt',
  44. );
  45. $allFiles = array(
  46. 'dir1/dir2/dir3/file31',
  47. 'dir1/dir2/dir4/file41',
  48. 'dir1/dir2/file21.php',
  49. 'dir1/dir2/file22',
  50. 'dir1/dir2/file23',
  51. 'dir1/dir2/file24',
  52. 'dir1/file11',
  53. 'dir1/file12.php',
  54. 'dir1/file13',
  55. 'file1',
  56. 'FILE5.txt',
  57. 'file2.txt',
  58. );
  59. $minDepth1Files = array(
  60. 'dir1/dir2/dir3/file31',
  61. 'dir1/dir2/dir4/file41',
  62. 'dir1/dir2/file21.php',
  63. 'dir1/dir2/file22',
  64. 'dir1/dir2/file23',
  65. 'dir1/dir2/file24',
  66. 'dir1/file11',
  67. 'dir1/file12.php',
  68. 'dir1/file13',
  69. );
  70. $maxDepth2Files = array(
  71. 'dir1/dir2/file21.php',
  72. 'dir1/dir2/file22',
  73. 'dir1/dir2/file23',
  74. 'dir1/dir2/file24',
  75. 'dir1/file11',
  76. 'dir1/file12.php',
  77. 'dir1/file13',
  78. 'file1',
  79. 'FILE5.txt',
  80. 'file2.txt',
  81. );
  82. $anyWithoutDir2 = array(
  83. 'dir1',
  84. 'dir1/dir2',
  85. 'dir1/file11',
  86. 'dir1/file12.php',
  87. 'dir1/file13',
  88. 'file1',
  89. 'FILE5.txt',
  90. 'file2.txt',
  91. );
  92. // ::type()
  93. $t->diag('::type()');
  94. $finder = sfFinder::type('file');
  95. $t->ok($finder instanceof sfFinder, '::type() returns a sfFinder instance');
  96. $t->is($finder->get_type(), 'file', '::type() takes a file, dir, or any as its first argument');
  97. $finder = sfFinder::type('dir');
  98. $t->is($finder->get_type(), 'directory', '::type() takes a file, dir, or any as its first argument');
  99. $finder = sfFinder::type('any');
  100. $t->is($finder->get_type(), 'any', '::type() takes a file, dir, or any as its first argument');
  101. $finder = sfFinder::type('somethingelse');
  102. $t->is($finder->get_type(), 'file', '::type() takes a file, dir, or any as its first argument');
  103. // ->setType() ->get_type()
  104. $t->diag('->setType() ->get_type()');
  105. $finder = sfFinder::type('file');
  106. $finder->setType('dir');
  107. $t->is($finder->get_type(), 'directory', '->getType() returns the type of searched files');
  108. $t->is($finder->setType('file'), $finder, '->setType() implements a fluent interface');
  109. // ->name()
  110. $t->diag('->name()');
  111. $finder = sfFinder::type('file');
  112. $t->is($finder->name('*.php'), $finder, '->name() implements the fluent interface');
  113. $t->diag('->name() file name support');
  114. $finder = sfFinder::type('file')->name('file21.php')->relative();
  115. $t->arrays_are_equal($finder->in($fixtureDir), array('dir1/dir2/file21.php'), '->name() can take a file name as an argument');
  116. $t->diag('->name() globs support');
  117. $finder = sfFinder::type('file')->name('*.php')->relative();
  118. $t->arrays_are_equal($finder->in($fixtureDir), $phpFiles, '->name() can take a glob pattern as an argument');
  119. $t->diag('->name() regexp support');
  120. $finder = sfFinder::type('file')->name('/^file2.*$/')->relative();
  121. $t->arrays_are_equal($finder->in($fixtureDir), $regexpFiles, '->name() can take a regexp as an argument');
  122. $t->diag('->name() regexp support with modifier');
  123. $finder = sfFinder::type('file')->name('/^file(2|5).*$/i')->relative();
  124. $t->arrays_are_equal($finder->in($fixtureDir), $regexpWithModifierFiles, '->name() can take a regexp with a modifier as an argument');
  125. $t->diag('->name() array / args / chaining');
  126. $finder = sfFinder::type('file')->name(array('*.php', '*.txt'))->relative();
  127. $t->arrays_are_equal($finder->in($fixtureDir), array_merge($phpFiles, $txtFiles), '->name() can take an array of patterns');
  128. $finder = sfFinder::type('file')->name('*.php', '*.txt')->relative();
  129. $t->arrays_are_equal($finder->in($fixtureDir), array_merge($phpFiles, $txtFiles), '->name() can take patterns as arguments');
  130. $finder = sfFinder::type('file')->name('*.php')->name('*.txt')->relative();
  131. $t->arrays_are_equal($finder->in($fixtureDir), array_merge($phpFiles, $txtFiles), '->name() can be called several times');
  132. // ->not_name()
  133. $t->diag('->not_name()');
  134. $finder = sfFinder::type('file');
  135. $t->is($finder->not_name('*.php'), $finder, '->not_name() implements the fluent interface');
  136. $t->diag('->not_name() file name support');
  137. $finder = sfFinder::type('file')->not_name('file21.php')->relative();
  138. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, array('dir1/dir2/file21.php'))), '->not_name() can take a file name as an argument');
  139. $t->diag('->not_name() globs support');
  140. $finder = sfFinder::type('file')->not_name('*.php')->relative();
  141. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, $phpFiles)), '->not_name() can take a glob pattern as an argument');
  142. $t->diag('->not_name() regexp support');
  143. $finder = sfFinder::type('file')->not_name('/^file2.*$/')->relative();
  144. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, $regexpFiles)), '->not_name() can take a regexp as an argument');
  145. $t->diag('->not_name() array / args / chaining');
  146. $finder = sfFinder::type('file')->not_name(array('*.php', '*.txt'))->relative();
  147. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, array_merge($phpFiles, $txtFiles))), '->not_name() can take an array of patterns');
  148. $finder = sfFinder::type('file')->not_name('*.php', '*.txt')->relative();
  149. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, array_merge($phpFiles, $txtFiles))), '->not_name() can take patterns as arguments');
  150. $finder = sfFinder::type('file')->not_name('*.php')->not_name('*.txt')->relative();
  151. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, array_merge($phpFiles, $txtFiles))), '->not_name() can be called several times');
  152. $t->diag('->name() ->not_name() in the same query');
  153. $finder = sfFinder::type('file')->not_name('/^file2.*$/')->name('*.php')->relative();
  154. $t->arrays_are_equal($finder->in($fixtureDir), array('dir1/file12.php'), '->not_name() and ->name() can be called in the same query');
  155. // ->size()
  156. $t->diag('->size()');
  157. $finder = sfFinder::type('file');
  158. $t->is($finder->size('> 2K'), $finder, '->size() implements the fluent interface');
  159. $finder = sfFinder::type('file')->size('> 100K')->relative();
  160. $t->is($finder->in($fixtureDir), array(), '->size() takes a size comparison string as its argument');
  161. $finder = sfFinder::type('file')->size('> 1K')->relative();
  162. $t->is($finder->in($fixtureDir), array('file1'), '->size() takes a size comparison string as its argument');
  163. $finder = sfFinder::type('file')->size('> 1K')->size('< 2K')->relative();
  164. $t->is($finder->in($fixtureDir), array(), '->size() takes a size comparison string as its argument');
  165. // ->mindepth() ->maxdepth()
  166. $t->diag('->mindepth() ->maxdepth()');
  167. $finder = sfFinder::type('file');
  168. $t->is($finder->mindepth(1), $finder, '->mindepth() implements the fluent interface');
  169. $t->is($finder->maxdepth(1), $finder, '->maxdepth() implements the fluent interface');
  170. $finder = sfFinder::type('file')->relative()->mindepth(1);
  171. $t->arrays_are_equal($finder->in($fixtureDir), $minDepth1Files, '->mindepth() takes a minimum depth as its argument');
  172. $finder = sfFinder::type('file')->relative()->maxdepth(2);
  173. $t->arrays_are_equal($finder->in($fixtureDir), $maxDepth2Files, '->maxdepth() takes a maximum depth as its argument');
  174. $finder = sfFinder::type('file')->relative()->mindepth(1)->maxdepth(2);
  175. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_intersect($minDepth1Files, $maxDepth2Files)), '->maxdepth() and ->mindepth() can be called in the same query');
  176. // ->discard()
  177. $t->diag('->discard()');
  178. $t->is($finder->discard('file2.txt'), $finder, '->discard() implements the fluent interface');
  179. $t->diag('->discard() file name support');
  180. $finder = sfFinder::type('file')->relative()->discard('file2.txt');
  181. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, array('file2.txt'))), '->discard() can discard a file name');
  182. $t->diag('->discard() glob support');
  183. $finder = sfFinder::type('file')->relative()->discard('*.php');
  184. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, $phpFiles)), '->discard() can discard a glob pattern');
  185. $t->diag('->discard() regexp support');
  186. $finder = sfFinder::type('file')->relative()->discard('/^file2.*$/');
  187. $t->arrays_are_equal($finder->in($fixtureDir), array_values(array_diff($allFiles, $regexpFiles)), '->discard() can discard a regexp pattern');
  188. // ->prune()
  189. $t->diag('->prune()');
  190. $t->is($finder->prune('dir2'), $finder, '->prune() implements the fluent interface');
  191. $finder = sfFinder::type('any')->relative()->prune('dir2');
  192. $t->arrays_are_equal($finder->in($fixtureDir), $anyWithoutDir2, '->prune() ignore all files/directories under the given directory');
  193. // ->in() permissions
  194. $t->diag('->in() permissions');
  195. chmod($fixtureDir.'_permissions/secret', 0000);
  196. $finder = sfFinder::type('file')->relative();
  197. $t->arrays_are_equal($finder->in($fixtureDir.'_permissions'), array(), '->in() ignores directories it cannot read');
  198. chmod($fixtureDir.'_permissions/secret', 0755);