b0223b782b6a66a4d8a391a99931a0cd4db95563
[yaffs-website] / vendor / symfony / finder / Tests / Iterator / RealIteratorTestCase.php
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             'toto/.git/',
35             'foo bar',
36         );
37
38         self::$files = self::toAbsolute(self::$files);
39
40         if (is_dir(self::$tmpDir)) {
41             self::tearDownAfterClass();
42         } else {
43             mkdir(self::$tmpDir);
44         }
45
46         foreach (self::$files as $file) {
47             if (\DIRECTORY_SEPARATOR === $file[\strlen($file) - 1]) {
48                 mkdir($file);
49             } else {
50                 touch($file);
51             }
52         }
53
54         file_put_contents(self::toAbsolute('test.php'), str_repeat(' ', 800));
55         file_put_contents(self::toAbsolute('test.py'), str_repeat(' ', 2000));
56
57         touch(self::toAbsolute('foo/bar.tmp'), strtotime('2005-10-15'));
58         touch(self::toAbsolute('test.php'), strtotime('2005-10-15'));
59     }
60
61     public static function tearDownAfterClass()
62     {
63         $paths = new \RecursiveIteratorIterator(
64              new \RecursiveDirectoryIterator(self::$tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS),
65              \RecursiveIteratorIterator::CHILD_FIRST
66          );
67
68         foreach ($paths as $path) {
69             if ($path->isDir()) {
70                 if ($path->isLink()) {
71                     @unlink($path);
72                 } else {
73                     @rmdir($path);
74                 }
75             } else {
76                 @unlink($path);
77             }
78         }
79     }
80
81     protected static function toAbsolute($files = null)
82     {
83         /*
84          * Without the call to setUpBeforeClass() property can be null.
85          */
86         if (!self::$tmpDir) {
87             self::$tmpDir = realpath(sys_get_temp_dir()).\DIRECTORY_SEPARATOR.'symfony_finder';
88         }
89
90         if (\is_array($files)) {
91             $f = array();
92             foreach ($files as $file) {
93                 if (\is_array($file)) {
94                     $f[] = self::toAbsolute($file);
95                 } else {
96                     $f[] = self::$tmpDir.\DIRECTORY_SEPARATOR.str_replace('/', \DIRECTORY_SEPARATOR, $file);
97                 }
98             }
99
100             return $f;
101         }
102
103         if (\is_string($files)) {
104             return self::$tmpDir.\DIRECTORY_SEPARATOR.str_replace('/', \DIRECTORY_SEPARATOR, $files);
105         }
106
107         return self::$tmpDir;
108     }
109
110     protected static function toAbsoluteFixtures($files)
111     {
112         $f = array();
113         foreach ($files as $file) {
114             $f[] = realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.$file);
115         }
116
117         return $f;
118     }
119 }