TYPO3  7.6
RealIteratorTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Finder\Tests\Iterator;
13 
14 abstract class RealIteratorTestCase extends IteratorTestCase
15 {
16  protected static $tmpDir;
17  protected static $files;
18 
19  public static function setUpBeforeClass()
20  {
21  self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
22 
23  self::$files = array(
24  '.git/',
25  '.foo/',
26  '.foo/.bar',
27  '.foo/bar',
28  '.bar',
29  'test.py',
30  'foo/',
31  'foo/bar.tmp',
32  'test.php',
33  'toto/',
34  'foo bar',
35  );
36 
37  self::$files = self::toAbsolute(self::$files);
38 
39  if (is_dir(self::$tmpDir)) {
40  self::tearDownAfterClass();
41  } else {
42  mkdir(self::$tmpDir);
43  }
44 
45  foreach (self::$files as $file) {
46  if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
47  mkdir($file);
48  } else {
49  touch($file);
50  }
51  }
52 
53  file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
54  file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));
55 
56  touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
57  touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
58  }
59 
60  public static function tearDownAfterClass()
61  {
62  foreach (array_reverse(self::$files) as $file) {
63  if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
64  @rmdir($file);
65  } else {
66  @unlink($file);
67  }
68  }
69  }
70 
71  protected static function toAbsolute($files = null)
72  {
73  /*
74  * Without the call to setUpBeforeClass() property can be null.
75  */
76  if (!self::$tmpDir) {
77  self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
78  }
79 
80  if (is_array($files)) {
81  $f = array();
82  foreach ($files as $file) {
83  if (is_array($file)) {
84  $f[] = self::toAbsolute($file);
85  } else {
86  $f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
87  }
88  }
89 
90  return $f;
91  }
92 
93  if (is_string($files)) {
94  return self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $files);
95  }
96 
97  return self::$tmpDir;
98  }
99 
100  protected static function toAbsoluteFixtures($files)
101  {
102  $f = array();
103  foreach ($files as $file) {
104  $f[] = realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file);
105  }
106 
107  return $f;
108  }
109 }