RealIteratorTestCase.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\Iterator;
  11. abstract class RealIteratorTestCase extends IteratorTestCase
  12. {
  13. protected static $tmpDir;
  14. protected static $files;
  15. public static function setUpBeforeClass()
  16. {
  17. self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
  18. self::$files = array(
  19. '.git/',
  20. '.foo/',
  21. '.foo/.bar',
  22. '.foo/bar',
  23. '.bar',
  24. 'test.py',
  25. 'foo/',
  26. 'foo/bar.tmp',
  27. 'test.php',
  28. 'toto/',
  29. 'toto/.git/',
  30. 'foo bar',
  31. );
  32. self::$files = self::toAbsolute(self::$files);
  33. if (is_dir(self::$tmpDir)) {
  34. self::tearDownAfterClass();
  35. } else {
  36. mkdir(self::$tmpDir);
  37. }
  38. foreach (self::$files as $file) {
  39. if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
  40. mkdir($file);
  41. } else {
  42. touch($file);
  43. }
  44. }
  45. file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
  46. file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));
  47. touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
  48. touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
  49. }
  50. public static function tearDownAfterClass()
  51. {
  52. foreach (array_reverse(self::$files) as $file) {
  53. if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
  54. @rmdir($file);
  55. } else {
  56. @unlink($file);
  57. }
  58. }
  59. }
  60. protected static function toAbsolute($files = null)
  61. {
  62. /*
  63. * Without the call to setUpBeforeClass() property can be null.
  64. */
  65. if (!self::$tmpDir) {
  66. self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
  67. }
  68. if (is_array($files)) {
  69. $f = array();
  70. foreach ($files as $file) {
  71. if (is_array($file)) {
  72. $f[] = self::toAbsolute($file);
  73. } else {
  74. $f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
  75. }
  76. }
  77. return $f;
  78. }
  79. if (is_string($files)) {
  80. return self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $files);
  81. }
  82. return self::$tmpDir;
  83. }
  84. protected static function toAbsoluteFixtures($files)
  85. {
  86. $f = array();
  87. foreach ($files as $file) {
  88. $f[] = realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file);
  89. }
  90. return $f;
  91. }
  92. }