@@ -198,6 +198,41 @@ public function can_create_image_with_dimensions(): void
198
198
$ this ->assertSame ('png ' , $ file ->getExtension ());
199
199
}
200
200
201
+ /**
202
+ * @test
203
+ */
204
+ public function can_create_image_with_name (): void
205
+ {
206
+ $ imageSize = \getimagesize ($ file = TempFile::image (5 , 6 , name: 'some-image.png ' ));
207
+
208
+ $ this ->assertFileExists ($ file );
209
+ $ this ->assertSame (\sys_get_temp_dir ().'/some-image.png ' , (string ) $ file );
210
+ $ this ->assertSame (5 , $ imageSize [0 ]);
211
+ $ this ->assertSame (6 , $ imageSize [1 ]);
212
+ $ this ->assertSame ('image/png ' , $ imageSize ['mime ' ]);
213
+ $ this ->assertSame ('png ' , $ file ->getExtension ());
214
+ }
215
+
216
+ /**
217
+ * @test
218
+ */
219
+ public function image_name_requires_extension (): void
220
+ {
221
+ $ this ->expectException (\InvalidArgumentException::class);
222
+
223
+ TempFile::image (name: 'some-image ' );
224
+ }
225
+
226
+ /**
227
+ * @test
228
+ */
229
+ public function image_name_cannot_contain_directory_separator (): void
230
+ {
231
+ $ this ->expectException (\InvalidArgumentException::class);
232
+
233
+ TempFile::image (name: 'some/dir/image.png ' );
234
+ }
235
+
201
236
/**
202
237
* @test
203
238
*/
@@ -207,4 +242,62 @@ public function cannot_create_image_for_invalid_type(): void
207
242
208
243
TempFile::image (type: 'invalid ' );
209
244
}
245
+
246
+ /**
247
+ * @test
248
+ */
249
+ public function can_create_named_temp_file (): void
250
+ {
251
+ $ file = TempFile::withName ('some-file.txt ' );
252
+
253
+ $ this ->assertFileExists ($ file );
254
+ $ this ->assertSame (\sys_get_temp_dir ().'/some-file.txt ' , (string ) $ file );
255
+ $ this ->assertSame ('' , \file_get_contents ($ file ));
256
+
257
+ TempFile::purge ();
258
+
259
+ $ this ->assertFileDoesNotExist ($ file );
260
+ }
261
+
262
+ /**
263
+ * @test
264
+ */
265
+ public function can_create_named_temp_file_with_string_content (): void
266
+ {
267
+ $ file = TempFile::withName ('some-file.txt ' , 'content ' );
268
+
269
+ $ this ->assertFileExists ($ file );
270
+ $ this ->assertSame (\sys_get_temp_dir ().'/some-file.txt ' , (string ) $ file );
271
+ $ this ->assertSame ('content ' , \file_get_contents ($ file ));
272
+
273
+ TempFile::purge ();
274
+
275
+ $ this ->assertFileDoesNotExist ($ file );
276
+ }
277
+
278
+ /**
279
+ * @test
280
+ */
281
+ public function can_create_named_temp_file_with_spl_file (): void
282
+ {
283
+ $ file = TempFile::withName ('some-file.txt ' , new \SplFileInfo (__FILE__ ));
284
+
285
+ $ this ->assertFileExists ($ file );
286
+ $ this ->assertSame (\sys_get_temp_dir ().'/some-file.txt ' , (string ) $ file );
287
+ $ this ->assertFileEquals ($ file , __FILE__ );
288
+
289
+ TempFile::purge ();
290
+
291
+ $ this ->assertFileDoesNotExist ($ file );
292
+ }
293
+
294
+ /**
295
+ * @test
296
+ */
297
+ public function name_cannot_contain_directory_separator (): void
298
+ {
299
+ $ this ->expectException (\InvalidArgumentException::class);
300
+
301
+ TempFile::withName ('some/dir/some-file.txt ' );
302
+ }
210
303
}
0 commit comments