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