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@0
|
21 self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
|
Chris@0
|
22
|
Chris@0
|
23 self::$files = array(
|
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@0
|
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@0
|
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@0
|
63 foreach (array_reverse(self::$files) as $file) {
|
Chris@0
|
64 if (DIRECTORY_SEPARATOR === $file[strlen($file) - 1]) {
|
Chris@0
|
65 @rmdir($file);
|
Chris@0
|
66 } else {
|
Chris@0
|
67 @unlink($file);
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 protected static function toAbsolute($files = null)
|
Chris@0
|
73 {
|
Chris@0
|
74 /*
|
Chris@0
|
75 * Without the call to setUpBeforeClass() property can be null.
|
Chris@0
|
76 */
|
Chris@0
|
77 if (!self::$tmpDir) {
|
Chris@0
|
78 self::$tmpDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'symfony_finder';
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 if (is_array($files)) {
|
Chris@0
|
82 $f = array();
|
Chris@0
|
83 foreach ($files as $file) {
|
Chris@0
|
84 if (is_array($file)) {
|
Chris@0
|
85 $f[] = self::toAbsolute($file);
|
Chris@0
|
86 } else {
|
Chris@0
|
87 $f[] = self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $file);
|
Chris@0
|
88 }
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 return $f;
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 if (is_string($files)) {
|
Chris@0
|
95 return self::$tmpDir.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $files);
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 return self::$tmpDir;
|
Chris@0
|
99 }
|
Chris@0
|
100
|
Chris@0
|
101 protected static function toAbsoluteFixtures($files)
|
Chris@0
|
102 {
|
Chris@0
|
103 $f = array();
|
Chris@0
|
104 foreach ($files as $file) {
|
Chris@0
|
105 $f[] = realpath(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.$file);
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 return $f;
|
Chris@0
|
109 }
|
Chris@0
|
110 }
|