@@ -217,28 +217,25 @@ public function getRelativePathDataProvider(): array
217
217
public function testIsDirectory (
218
218
string $ path ,
219
219
string $ normalizedPath ,
220
- bool $ has ,
221
220
array $ metadata ,
222
221
bool $ expected ,
223
222
iterable $ listContents ,
224
- \Exception $ metadataException = null
223
+ \Throwable $ listContentsException = null
225
224
): void {
226
- $ this ->adapterMock ->method ('fileExists ' )
227
- ->with ($ normalizedPath )
228
- ->willReturn ($ has );
229
- $ this ->adapterMock ->method ('listContents ' )
230
- ->with ($ normalizedPath )
231
- ->willReturn ($ listContents );
232
- if (!$ metadataException ) {
225
+ if (!empty ($ metadata )) {
233
226
$ this ->metadataProviderMock ->method ('getMetadata ' )
234
227
->with ($ normalizedPath )
235
228
->willReturn ($ metadata );
229
+ }
230
+ if ($ listContentsException ) {
231
+ $ this ->adapterMock ->method ('listContents ' )
232
+ ->with ($ normalizedPath )
233
+ ->willThrowException ($ listContentsException );
236
234
} else {
237
- $ this ->metadataProviderMock ->method ('getMetadata ' )
235
+ $ this ->adapterMock ->method ('listContents ' )
238
236
->with ($ normalizedPath )
239
- ->willThrowException ( $ metadataException );
237
+ ->willReturn ( $ listContents );
240
238
}
241
-
242
239
self ::assertSame ($ expected , $ this ->driver ->isDirectory ($ path ));
243
240
}
244
241
@@ -251,16 +248,14 @@ public function isDirectoryDataProvider(): array
251
248
'empty metadata ' => [
252
249
'some_directory/ ' ,
253
250
'some_directory ' ,
254
- false ,
255
251
[],
256
252
false ,
257
253
new \ArrayIterator ([]),
258
- new UnableToRetrieveMetadata ( ' Can not fetch metadata. ' )
254
+ new \ Exception ( ' Closed iterator ' ),
259
255
],
260
256
[
261
257
'some_directory ' ,
262
258
'some_directory ' ,
263
- true ,
264
259
[
265
260
'type ' => AwsS3::TYPE_DIR
266
261
],
@@ -270,38 +265,29 @@ public function isDirectoryDataProvider(): array
270
265
[
271
266
self ::URL . 'some_directory ' ,
272
267
'some_directory ' ,
273
- true ,
274
268
[
275
269
'type ' => AwsS3::TYPE_DIR
276
270
],
277
271
true ,
278
272
new \ArrayIterator (['some_directory ' ]),
279
273
],
280
- [
281
- self ::URL . 'some_directory ' ,
282
- 'some_directory ' ,
283
- true ,
284
- [
285
- 'type ' => AwsS3::TYPE_FILE
286
- ],
287
- false ,
288
- new \ArrayIterator (['some_directory ' ]),
289
- ],
290
274
[
291
275
'' ,
292
276
'' ,
277
+ [
278
+ 'type ' => AwsS3::TYPE_DIR
279
+ ],
293
280
true ,
294
- [],
295
- true ,
296
- new \ArrayIterator (['some_directory ' ]),
281
+ new \ArrayIterator (['' ]),
297
282
],
298
283
[
299
284
'/ ' ,
300
285
'' ,
286
+ [
287
+ 'type ' => AwsS3::TYPE_DIR
288
+ ],
301
289
true ,
302
- [],
303
- true ,
304
- new \ArrayIterator (['some_directory ' ]),
290
+ new \ArrayIterator (['' ]),
305
291
],
306
292
];
307
293
}
@@ -433,19 +419,18 @@ public function testSearchDirectory(): void
433
419
$ expression = '/* ' ;
434
420
$ path = 'path ' ;
435
421
$ subPaths = [
436
- new \League \Flysystem \DirectoryAttributes ('path/1 ' ),
437
- new \League \Flysystem \DirectoryAttributes ('path/2 ' )
422
+ new \League \Flysystem \DirectoryAttributes ('path/1/ ' ),
423
+ new \League \Flysystem \DirectoryAttributes ('path/2/ ' )
438
424
];
439
- $ expectedResult = [self ::URL . 'path/1 ' , self ::URL . 'path/2 ' ];
440
- $ this ->metadataProviderMock ->expects (self ::atLeastOnce ())->method ('getMetadata ' )
425
+ $ expectedResult = [self ::URL . 'path/1/ ' , self ::URL . 'path/2/ ' ];
426
+ $ this ->metadataProviderMock ->expects (self ::any ())->method ('getMetadata ' )
441
427
->willReturnMap ([
442
428
['path ' , ['type ' => AwsS3::TYPE_DIR ]],
443
429
['path/1 ' , ['type ' => AwsS3::TYPE_FILE ]],
444
430
['path/2 ' , ['type ' => AwsS3::TYPE_FILE ]],
445
431
]);
446
432
$ this ->adapterMock ->expects (self ::atLeastOnce ())->method ('listContents ' )
447
- ->with ($ path , false )
448
- ->willReturn ($ subPaths );
433
+ ->willReturn (new \ArrayIterator ($ subPaths ));
449
434
450
435
self ::assertEquals ($ expectedResult , $ this ->driver ->search ($ expression , $ path ));
451
436
}
@@ -468,7 +453,7 @@ public function testSearchFiles(): void
468
453
['path/1.jpg ' , ['type ' => AwsS3::TYPE_FILE ]],
469
454
['path/2.png ' , ['type ' => AwsS3::TYPE_FILE ]],
470
455
]);
471
- $ this ->adapterMock ->expects (self ::atLeastOnce ())->method ('listContents ' )-> with ( $ path , false )
456
+ $ this ->adapterMock ->expects (self ::atLeastOnce ())->method ('listContents ' )
472
457
->willReturn ($ subPaths );
473
458
474
459
self ::assertEquals ($ expectedResult , $ this ->driver ->search ($ expression , $ path ));
0 commit comments