1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<?php
/* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\SortableIterator;
class SortableIteratorTest extends RealIteratorTestCase { public function testConstructor() { try { new SortableIterator(new Iterator(array()), 'foobar'); $this->fail('__construct() throws an \InvalidArgumentException exception if the mode is not valid'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException exception if the mode is not valid'); } }
/** * @dataProvider getAcceptData */ public function testAccept($mode, $expected) { if (!is_callable($mode)) { switch ($mode) { case SortableIterator::SORT_BY_ACCESSED_TIME: if ('\\' === DIRECTORY_SEPARATOR) { touch(self::toAbsolute('.git')); } else { file_get_contents(self::toAbsolute('.git')); } sleep(1); file_get_contents(self::toAbsolute('.bar')); break; case SortableIterator::SORT_BY_CHANGED_TIME: file_put_contents(self::toAbsolute('test.php'), 'foo'); sleep(1); file_put_contents(self::toAbsolute('test.py'), 'foo'); break; case SortableIterator::SORT_BY_MODIFIED_TIME: file_put_contents(self::toAbsolute('test.php'), 'foo'); sleep(1); file_put_contents(self::toAbsolute('test.py'), 'foo'); break; } }
$inner = new Iterator(self::$files);
$iterator = new SortableIterator($inner, $mode);
if ($mode === SortableIterator::SORT_BY_ACCESSED_TIME || $mode === SortableIterator::SORT_BY_CHANGED_TIME || $mode === SortableIterator::SORT_BY_MODIFIED_TIME ) { if ('\\' === DIRECTORY_SEPARATOR && SortableIterator::SORT_BY_MODIFIED_TIME !== $mode) { $this->markTestSkipped('Sorting by atime or ctime is not supported on Windows'); } $this->assertOrderedIteratorForGroups($expected, $iterator); } else { $this->assertOrderedIterator($expected, $iterator); } }
public function getAcceptData() { $sortByName = array( '.bar', '.foo', '.foo/.bar', '.foo/bar', '.git', 'foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', );
$sortByType = array( '.foo', '.git', 'foo', 'toto', 'toto/.git', '.bar', '.foo/.bar', '.foo/bar', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', );
$customComparison = array( '.bar', '.foo', '.foo/.bar', '.foo/bar', '.git', 'foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', );
$sortByAccessedTime = array( // For these two files the access time was set to 2005-10-15 array('foo/bar.tmp', 'test.php'), // These files were created more or less at the same time array( '.git', '.foo', '.foo/.bar', '.foo/bar', 'test.py', 'foo', 'toto', 'toto/.git', 'foo bar', ), // This file was accessed after sleeping for 1 sec array('.bar'), );
$sortByChangedTime = array( array( '.git', '.foo', '.foo/.bar', '.foo/bar', '.bar', 'foo', 'foo/bar.tmp', 'toto', 'toto/.git', 'foo bar', ), array('test.php'), array('test.py'), );
$sortByModifiedTime = array( array( '.git', '.foo', '.foo/.bar', '.foo/bar', '.bar', 'foo', 'foo/bar.tmp', 'toto', 'toto/.git', 'foo bar', ), array('test.php'), array('test.py'), );
return array( array(SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)), array(SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)), array(SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)), array(SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)), array(SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)), array(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)), ); } }
|