/vendor/symfony/symfony/src/Symfony/Component/Finder/Tests/Iterator/RealIteratorTestCase.php

https://github.com/nattaphat/hgis · PHP · 108 lines · 76 code · 21 blank · 11 comment · 9 complexity · 80a634cd182785eb07fb3a59ea42d027 MD5 · raw file

  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 . 'symfony2_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. 'foo bar'
  30. );
  31. self::$files = self::toAbsolute(self::$files);
  32. if (is_dir(self::$tmpDir)) {
  33. self::tearDownAfterClass();
  34. } else {
  35. mkdir(self::$tmpDir);
  36. }
  37. foreach (self::$files as $file) {
  38. if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
  39. mkdir($file);
  40. } else {
  41. touch($file);
  42. }
  43. }
  44. file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
  45. file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));
  46. touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
  47. touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
  48. }
  49. public static function tearDownAfterClass()
  50. {
  51. foreach (array_reverse(self::$files) as $file) {
  52. if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
  53. @rmdir($file);
  54. } else {
  55. @unlink($file);
  56. }
  57. }
  58. }
  59. protected static function toAbsolute($files = null)
  60. {
  61. /*
  62. * Without the call to setUpBeforeClass() property can be null.
  63. */
  64. if (!self::$tmpDir) {
  65. self::$tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'symfony2_finder';
  66. }
  67. if (is_array($files)) {
  68. $f = array();
  69. foreach ($files as $file) {
  70. $f[] = self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
  71. }
  72. return $f;
  73. }
  74. if (is_string($files)) {
  75. return self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $files);
  76. }
  77. return self::$tmpDir;
  78. }
  79. protected static function toAbsoluteFixtures($files)
  80. {
  81. $f = array();
  82. foreach ($files as $file) {
  83. $f[] = realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file);
  84. }
  85. return $f;
  86. }
  87. }