@@ -215,4 +215,70 @@ public function testFileOpen(): void
215
215
self ::$ fsockopen = $ fsockopenResult ;
216
216
$ this ->assertEquals ($ fsockopenResult , (new Http ())->fileOpen ('example.com ' , 'r ' ));
217
217
}
218
+
219
+ /**
220
+ * Test for getMetaData
221
+ *
222
+ * @dataProvider dataProviderForTestGetMetaData
223
+ * @param string $filePath
224
+ * @param array $headers
225
+ * @param array $expected
226
+ *
227
+ * @throws FileSystemException
228
+ */
229
+ public function testGetMetadata ($ filePath , $ headers , $ expected ): void
230
+ {
231
+ self ::$ headers = $ headers ;
232
+ $ http = new Http ();
233
+ if (strpos ($ headers [0 ], '200 OK ' ) === false ) {
234
+ $ this ->expectException (FileSystemException::class);
235
+ $ this ->expectExceptionMessage ('File \'' . $ filePath . '\' doesn \'t exist ' );
236
+ $ http ->getMetadata ($ filePath );
237
+ } else {
238
+ $ metadata = $ http ->getMetadata ($ filePath );
239
+ $ this ->assertEquals ($ metadata , $ expected );
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Data provider for testGetMetaData
245
+ *
246
+ * @return array
247
+ */
248
+ public function dataProviderForTestGetMetaData (): array
249
+ {
250
+ return [
251
+ 'existing file ' => [
252
+ 'file_path ' => 'example.com/file/1.pdf ' ,
253
+ 'headers ' => [
254
+ 0 => 'HTTP/1.0 200 OK ' ,
255
+ 'Content-Length ' => 128 ,
256
+ 'Content-Type ' => 'application/pdf ' ,
257
+ 'Last-Modified ' => 'Sat, 31 Mar 2021 01:36:20 GMT ' ,
258
+ 'Content-Disposition ' => 1024 ,
259
+ ],
260
+ 'expected ' => [
261
+ 'path ' => 'example.com/file ' ,
262
+ 'dirname ' => 'example.com ' ,
263
+ 'basename ' => '1.pdf ' ,
264
+ 'extension ' => 'pdf ' ,
265
+ 'filename ' => '1.pdf ' ,
266
+ 'timestamp ' => 1617413780 ,
267
+ 'size ' => 128 ,
268
+ 'mimetype ' => 'application/pdf ' ,
269
+ 'extra ' => [
270
+ 'image-width ' => 0 ,
271
+ 'image-height ' => 0
272
+ ]
273
+ ]
274
+ ],
275
+ 'non-existent file ' => [
276
+ 'file_path ' => 'example.com/file/2.pdf ' ,
277
+ 'headers ' => [
278
+ 0 => 'HTTP/1.0 404 Not Found '
279
+ ],
280
+ 'expected ' => []
281
+ ]
282
+ ];
283
+ }
218
284
}
0 commit comments