|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace uuf6429\ElderBrother\Action; |
|
4
|
|
|
|
|
5
|
|
|
use uuf6429\ElderBrother\BaseProjectTest; |
|
6
|
|
|
use uuf6429\ElderBrother\Change; |
|
7
|
|
|
|
|
8
|
|
|
class FileListTest extends BaseProjectTest |
|
9
|
|
|
{ |
|
10
|
|
|
public static function setUpBeforeClass() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setUpBeforeClass(); |
|
13
|
|
|
|
|
14
|
|
|
foreach ( |
|
15
|
|
|
[ |
|
16
|
|
|
'src/Acme/Combinator.php' => '<?php namespace Acme; class Combinator {}', |
|
17
|
|
|
'src/Acme/Comparator.php' => '<?php namespace Acme; class Comparator {}', |
|
18
|
|
|
'src/Acme/config.yml' => '', |
|
19
|
|
|
'test/Acme/data.dml' => '', |
|
20
|
|
|
'test/Acme/AcmeTest.php' => '<?php namespace Acme; class AcmeTest extends \PHPUnit_Framework_TestCase {}', |
|
21
|
|
|
'README' => 'Please read me!', |
|
22
|
|
|
'LICENSE' => 'Copyright 1986', |
|
23
|
|
|
'CONTRIBUTE' => 'Meh.', |
|
24
|
|
|
] as $filename => $content |
|
25
|
|
|
) { |
|
26
|
|
|
if (!is_dir(dirname($filename))) { |
|
27
|
|
|
mkdir(dirname($filename), 0755, true); |
|
28
|
|
|
} |
|
29
|
|
|
file_put_contents($filename, $content); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string[] $expectedItems |
|
35
|
|
|
* @param \Closure $itemsProvider |
|
36
|
|
|
* |
|
37
|
|
|
* @dataProvider fileListQueryDataProvider |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testFileListQuery($expectedItems, $itemsProvider) |
|
40
|
|
|
{ |
|
41
|
|
|
$baseDir = getcwd(); |
|
42
|
|
|
$actualItems = array_map( |
|
43
|
|
|
function ($file) use ($baseDir) { |
|
44
|
|
|
return str_replace([$baseDir . DIRECTORY_SEPARATOR, '\\'], ['', '/'], $file); |
|
45
|
|
|
}, |
|
46
|
|
|
$itemsProvider() |
|
47
|
|
|
); |
|
48
|
|
|
sort($actualItems); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertEquals($expectedItems, $actualItems); |
|
51
|
|
|
$this->assertSame($expectedItems, $actualItems); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function fileListQueryDataProvider() |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
// tests for filesystem item type |
|
61
|
|
|
'files' => [ |
|
62
|
|
|
'$expectedItems' => [ |
|
63
|
|
|
'CONTRIBUTE', |
|
64
|
|
|
'LICENSE', |
|
65
|
|
|
'README', |
|
66
|
|
|
'src/Acme/Combinator.php', |
|
67
|
|
|
'src/Acme/Comparator.php', |
|
68
|
|
|
'src/Acme/config.yml', |
|
69
|
|
|
'test/Acme/AcmeTest.php', |
|
70
|
|
|
'test/Acme/data.dml', |
|
71
|
|
|
], |
|
72
|
|
|
'$itemsProvider' => function () { |
|
73
|
|
|
return Change\FullChangeSet::get()->files()->toArray(); |
|
74
|
|
|
}, |
|
75
|
|
|
], |
|
76
|
|
|
'directories' => [ |
|
77
|
|
|
'$expectedItems' => [ |
|
78
|
|
|
'src', |
|
79
|
|
|
'src/Acme', |
|
80
|
|
|
'test', |
|
81
|
|
|
'test/Acme', |
|
82
|
|
|
], |
|
83
|
|
|
'$itemsProvider' => function () { |
|
84
|
|
|
return Change\FullChangeSet::get()->directories()->toArray(); |
|
85
|
|
|
}, |
|
86
|
|
|
], |
|
87
|
|
|
|
|
88
|
|
|
// tests for file name / path patterns |
|
89
|
|
|
'php files' => [ |
|
90
|
|
|
'$expectedItems' => [ |
|
91
|
|
|
'src/Acme/Combinator.php', |
|
92
|
|
|
'src/Acme/Comparator.php', |
|
93
|
|
|
'test/Acme/AcmeTest.php', |
|
94
|
|
|
], |
|
95
|
|
|
'$itemsProvider' => function () { |
|
96
|
|
|
return Change\FullChangeSet::get()->name('*.php')->toArray(); |
|
97
|
|
|
}, |
|
98
|
|
|
], |
|
99
|
|
|
'all items in src (3 files + 1 dir)' => [ |
|
100
|
|
|
'$expectedItems' => [ |
|
101
|
|
|
'src/Acme', |
|
102
|
|
|
'src/Acme/Combinator.php', |
|
103
|
|
|
'src/Acme/Comparator.php', |
|
104
|
|
|
'src/Acme/config.yml', |
|
105
|
|
|
], |
|
106
|
|
|
'$itemsProvider' => function () { |
|
107
|
|
|
return Change\FullChangeSet::get()->path('src/')->toArray(); |
|
108
|
|
|
}, |
|
109
|
|
|
], |
|
110
|
|
|
'all items with Acme in their pathname' => [ |
|
111
|
|
|
'$expectedItems' => [ |
|
112
|
|
|
'src/Acme', |
|
113
|
|
|
'test/Acme', |
|
114
|
|
|
], |
|
115
|
|
|
'$itemsProvider' => function () { |
|
116
|
|
|
return Change\FullChangeSet::get()->name('Acme')->toArray(); |
|
117
|
|
|
}, |
|
118
|
|
|
], |
|
119
|
|
|
'all php files not in src/' => [ |
|
120
|
|
|
'$expectedItems' => [ |
|
121
|
|
|
'test/Acme/AcmeTest.php', |
|
122
|
|
|
], |
|
123
|
|
|
'$itemsProvider' => function () { |
|
124
|
|
|
return Change\FullChangeSet::get()->notPath('src/')->name('*.php')->toArray(); |
|
125
|
|
|
}, |
|
126
|
|
|
], |
|
127
|
|
|
|
|
128
|
|
|
// tests for file contents |
|
129
|
|
|
'files containing "class"' => [ |
|
130
|
|
|
'$expectedItems' => [ |
|
131
|
|
|
'src/Acme/Combinator.php', |
|
132
|
|
|
'src/Acme/Comparator.php', |
|
133
|
|
|
'test/Acme/AcmeTest.php', |
|
134
|
|
|
], |
|
135
|
|
|
'$itemsProvider' => function () { |
|
136
|
|
|
return Change\FullChangeSet::get()->contains('class')->toArray(); |
|
137
|
|
|
}, |
|
138
|
|
|
], |
|
139
|
|
|
'base classes' => [ |
|
140
|
|
|
'$expectedItems' => [ |
|
141
|
|
|
'src/Acme/Combinator.php', |
|
142
|
|
|
'src/Acme/Comparator.php', |
|
143
|
|
|
], |
|
144
|
|
|
'$itemsProvider' => function () { |
|
145
|
|
|
return Change\FullChangeSet::get() |
|
146
|
|
|
->name('*.php') |
|
147
|
|
|
->notContains('/extends\\s+([\\w_\\\\]+)\\s*\\{/') |
|
148
|
|
|
->toArray(); |
|
149
|
|
|
}, |
|
150
|
|
|
], |
|
151
|
|
|
'phpunit test classes' => [ |
|
152
|
|
|
'$expectedItems' => [ |
|
153
|
|
|
'test/Acme/AcmeTest.php', |
|
154
|
|
|
], |
|
155
|
|
|
'$itemsProvider' => function () { |
|
156
|
|
|
return Change\FullChangeSet::get() |
|
157
|
|
|
->name('*.php') |
|
158
|
|
|
->contains('/class\\s+([\\w_]+)\\s+extends\\s\\\\?PHPUnit_Framework_TestCase\\s*{/') |
|
159
|
|
|
->toArray(); |
|
160
|
|
|
}, |
|
161
|
|
|
], |
|
162
|
|
|
|
|
163
|
|
|
// tests for custom filter |
|
164
|
|
|
'filter for some files' => [ |
|
165
|
|
|
'$expectedItems' => [ |
|
166
|
|
|
'CONTRIBUTE', |
|
167
|
|
|
'LICENSE', |
|
168
|
|
|
'README', |
|
169
|
|
|
], |
|
170
|
|
|
'$itemsProvider' => function () { |
|
171
|
|
|
return Change\FullChangeSet::get() |
|
172
|
|
|
->filter( |
|
173
|
|
|
function (\SplFileInfo $file) { |
|
174
|
|
|
return in_array($file->getFilename(), ['README', 'LICENSE', 'CONTRIBUTE']); |
|
175
|
|
|
} |
|
176
|
|
|
) |
|
177
|
|
|
->toArray(); |
|
178
|
|
|
}, |
|
179
|
|
|
], |
|
180
|
|
|
|
|
181
|
|
|
// tests for path depth |
|
182
|
|
|
'top level files' => [ |
|
183
|
|
|
'$expectedItems' => [ |
|
184
|
|
|
'CONTRIBUTE', |
|
185
|
|
|
'LICENSE', |
|
186
|
|
|
'README', |
|
187
|
|
|
], |
|
188
|
|
|
'$itemsProvider' => function () { |
|
189
|
|
|
return Change\FullChangeSet::get()->files()->depth('< 2')->toArray(); |
|
190
|
|
|
}, |
|
191
|
|
|
], |
|
192
|
|
|
'top level directories' => [ |
|
193
|
|
|
'$expectedItems' => [ |
|
194
|
|
|
'src', |
|
195
|
|
|
'src/Acme', |
|
196
|
|
|
'test', |
|
197
|
|
|
'test/Acme', |
|
198
|
|
|
], |
|
199
|
|
|
'$itemsProvider' => function () { |
|
200
|
|
|
return Change\FullChangeSet::get()->directories()->depth('< 2')->toArray(); |
|
201
|
|
|
}, |
|
202
|
|
|
], |
|
203
|
|
|
'deep items' => [ |
|
204
|
|
|
'$expectedItems' => [ |
|
205
|
|
|
'src/Acme/Combinator.php', |
|
206
|
|
|
'src/Acme/Comparator.php', |
|
207
|
|
|
'src/Acme/config.yml', |
|
208
|
|
|
'test/Acme/AcmeTest.php', |
|
209
|
|
|
'test/Acme/data.dml', |
|
210
|
|
|
], |
|
211
|
|
|
'$itemsProvider' => function () { |
|
212
|
|
|
return Change\FullChangeSet::get()->depth('> 1')->toArray(); |
|
213
|
|
|
}, |
|
214
|
|
|
], |
|
215
|
|
|
]; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|