@@ -39,13 +39,17 @@ protected function tearDown(): void
39
39
*/
40
40
public function testAccept (array $ gitIgnoreFiles , array $ otherFileNames , array $ expectedResult )
41
41
{
42
- foreach ($ gitIgnoreFiles as $ path => $ content ) {
43
- $ this ->createFile ("{$ this ->tmpDir }/ {$ path }" , $ content );
44
- }
45
-
46
42
$ otherFileNames = $ this ->toAbsolute ($ otherFileNames );
47
43
foreach ($ otherFileNames as $ path ) {
48
- $ this ->createFile ($ path );
44
+ if (str_ends_with ($ path , '/ ' )) {
45
+ mkdir ($ path );
46
+ } else {
47
+ touch ($ path );
48
+ }
49
+ }
50
+
51
+ foreach ($ gitIgnoreFiles as $ path => $ content ) {
52
+ file_put_contents ("{$ this ->tmpDir }/ {$ path }" , $ content );
49
53
}
50
54
51
55
$ inner = new InnerNameIterator ($ otherFileNames );
@@ -64,10 +68,12 @@ public function getAcceptData(): iterable
64
68
[
65
69
'a.txt ' ,
66
70
'b.txt ' ,
71
+ 'dir/ ' ,
67
72
'dir/a.txt ' ,
68
73
],
69
74
[
70
75
'b.txt ' ,
76
+ 'dir ' ,
71
77
],
72
78
];
73
79
@@ -78,20 +84,23 @@ public function getAcceptData(): iterable
78
84
[
79
85
'a.txt ' ,
80
86
'b.txt ' ,
87
+ 'dir/ ' ,
81
88
'dir/a.txt ' ,
82
89
],
83
90
[
84
91
'b.txt ' ,
92
+ 'dir ' ,
85
93
'dir/a.txt ' ,
86
94
],
87
95
];
88
96
89
- yield 'directy ' => [
97
+ yield 'directory ' => [
90
98
[
91
99
'.gitignore ' => 'dir/ ' ,
92
100
],
93
101
[
94
102
'a.txt ' ,
103
+ 'dir/ ' ,
95
104
'dir/a.txt ' ,
96
105
'dir/b.txt ' ,
97
106
],
@@ -100,7 +109,7 @@ public function getAcceptData(): iterable
100
109
],
101
110
];
102
111
103
- yield 'directy matching a file ' => [
112
+ yield 'directory matching a file ' => [
104
113
[
105
114
'.gitignore ' => 'dir.txt/ ' ,
106
115
],
@@ -112,15 +121,20 @@ public function getAcceptData(): iterable
112
121
],
113
122
];
114
123
115
- yield 'directy at root ' => [
124
+ yield 'directory at root ' => [
116
125
[
117
126
'.gitignore ' => '/dir/ ' ,
118
127
],
119
128
[
129
+ 'dir/ ' ,
120
130
'dir/a.txt ' ,
131
+ 'other/ ' ,
132
+ 'other/dir/ ' ,
121
133
'other/dir/b.txt ' ,
122
134
],
123
135
[
136
+ 'other ' ,
137
+ 'other/dir ' ,
124
138
'other/dir/b.txt ' ,
125
139
],
126
140
];
@@ -131,11 +145,15 @@ public function getAcceptData(): iterable
131
145
],
132
146
[
133
147
'a.txt ' ,
148
+ 'nested/ ' ,
134
149
'nested/a.txt ' ,
150
+ 'nested/nested/ ' ,
135
151
'nested/nested/a.txt ' ,
136
152
],
137
153
[
138
154
'a.txt ' ,
155
+ 'nested ' ,
156
+ 'nested/nested ' ,
139
157
],
140
158
];
141
159
@@ -145,58 +163,81 @@ public function getAcceptData(): iterable
145
163
],
146
164
[
147
165
'a.txt ' ,
166
+ 'nested/ ' ,
148
167
'nested/a.txt ' ,
168
+ 'nested/nested/ ' ,
149
169
'nested/nested/a.txt ' ,
150
170
],
151
171
[
152
172
'a.txt ' ,
173
+ 'nested ' ,
174
+ 'nested/nested ' ,
153
175
'nested/nested/a.txt ' ,
154
176
],
155
177
];
156
178
157
- yield 'directy in nested .gitignore ' => [
179
+ yield 'directory in nested .gitignore ' => [
158
180
[
159
181
'nested/.gitignore ' => 'dir/ ' ,
160
182
],
161
183
[
162
184
'a.txt ' ,
185
+ 'dir/ ' ,
163
186
'dir/a.txt ' ,
187
+ 'nested/ ' ,
188
+ 'nested/dir/ ' ,
164
189
'nested/dir/a.txt ' ,
190
+ 'nested/nested/ ' ,
191
+ 'nested/nested/dir/ ' ,
165
192
'nested/nested/dir/a.txt ' ,
166
193
],
167
194
[
168
195
'a.txt ' ,
196
+ 'dir ' ,
169
197
'dir/a.txt ' ,
198
+ 'nested ' ,
199
+ 'nested/nested ' ,
170
200
],
171
201
];
172
202
173
- yield 'directy matching a file in nested .gitignore ' => [
203
+ yield 'directory matching a file in nested .gitignore ' => [
174
204
[
175
205
'nested/.gitignore ' => 'dir.txt/ ' ,
176
206
],
177
207
[
178
208
'dir.txt ' ,
209
+ 'nested/ ' ,
179
210
'nested/dir.txt ' ,
180
211
],
181
212
[
182
213
'dir.txt ' ,
214
+ 'nested ' ,
183
215
'nested/dir.txt ' ,
184
216
],
185
217
];
186
218
187
- yield 'directy at root of nested .gitignore ' => [
219
+ yield 'directory at root of nested .gitignore ' => [
188
220
[
189
221
'nested/.gitignore ' => '/dir/ ' ,
190
222
],
191
223
[
192
224
'a.txt ' ,
225
+ 'dir/ ' ,
193
226
'dir/a.txt ' ,
227
+ 'nested/ ' ,
228
+ 'nested/dir/ ' ,
194
229
'nested/dir/a.txt ' ,
230
+ 'nested/nested/ ' ,
231
+ 'nested/nested/dir/ ' ,
195
232
'nested/nested/dir/a.txt ' ,
196
233
],
197
234
[
198
235
'a.txt ' ,
236
+ 'dir ' ,
199
237
'dir/a.txt ' ,
238
+ 'nested ' ,
239
+ 'nested/nested ' ,
240
+ 'nested/nested/dir ' ,
200
241
'nested/nested/dir/a.txt ' ,
201
242
],
202
243
];
@@ -209,12 +250,15 @@ public function getAcceptData(): iterable
209
250
[
210
251
'a.txt ' ,
211
252
'b.txt ' ,
253
+ 'nested/ ' ,
212
254
'nested/a.txt ' ,
213
255
'nested/b.txt ' ,
256
+ 'nested/dir/ ' ,
214
257
'nested/dir/a.txt ' ,
215
258
'nested/dir/b.txt ' ,
216
259
],
217
260
[
261
+ 'nested ' ,
218
262
'nested/a.txt ' ,
219
263
],
220
264
];
@@ -227,8 +271,10 @@ public function getAcceptData(): iterable
227
271
[
228
272
'a.txt ' ,
229
273
'b.txt ' ,
274
+ 'nested/ ' ,
230
275
'nested/a.txt ' ,
231
276
'nested/b.txt ' ,
277
+ 'nested/dir/ ' ,
232
278
'nested/dir/a.txt ' ,
233
279
'nested/dir/b.txt ' ,
234
280
],
@@ -241,9 +287,15 @@ public function getAcceptData(): iterable
241
287
'a/.gitignore ' => '!c/ ' ,
242
288
],
243
289
[
290
+ 'a/ ' ,
291
+ 'a/b/ ' ,
292
+ 'a/b/c/ ' ,
244
293
'a/b/c/d.txt ' ,
245
294
],
246
295
[
296
+ 'a ' ,
297
+ 'a/b ' ,
298
+ 'a/b/c ' ,
247
299
'a/b/c/d.txt ' ,
248
300
],
249
301
];
@@ -253,6 +305,7 @@ public function getAcceptData(): iterable
253
305
'.gitignore ' => "/a/** \n!/a/b.txt " ,
254
306
],
255
307
[
308
+ 'a/ ' ,
256
309
'a/a.txt ' ,
257
310
'a/b.txt ' ,
258
311
'a/c.txt ' ,
@@ -281,20 +334,6 @@ private function toAbsolute(array $files): array
281
334
return $ files ;
282
335
}
283
336
284
- private function createFile (string $ path , string $ content = null ): void
285
- {
286
- $ dir = \dirname ($ path );
287
- if (!file_exists ($ dir )) {
288
- mkdir ($ dir , 0777 , true );
289
- }
290
-
291
- if (null !== $ content ) {
292
- file_put_contents ($ path , $ content );
293
- } else {
294
- touch ($ path );
295
- }
296
- }
297
-
298
337
private function removeDirectory (string $ dir ): void
299
338
{
300
339
foreach ((new Finder ())->in ($ dir )->ignoreDotFiles (false )->depth ('< 1 ' ) as $ file ) {
0 commit comments