1111 */
1212final class ImageTest extends TestCase
1313{
14- private $ sourceFilesDir ;
15- private $ tempDir ;
16-
17- public function setUp ()
18- {
19- $ this ->sourceFilesDir = __DIR__ . '/_files ' ;
20- $ this ->tempDir = sys_get_temp_dir () . '/imageUtilTest ' ;
21- if (is_dir ($ this ->tempDir )) {
22- foreach (glob ("{$ this ->tempDir }/* " ) as $ file ) {
23- unlink ($ file );
24- }
25-
26- rmdir ($ this ->tempDir );
27- }
28- }
14+ private $ sourceFilesDir = __DIR__ . '/_files ' ;
15+ private $ tempDir = '/tmp/image-util ' ;
2916
3017 /**
3118 * Downsize ratio 2.0 to 0.25
@@ -267,107 +254,107 @@ public function resizeWithBurredBackgroundWithCustomBlurValue()
267254 * @test
268255 * @covers ::resize
269256 * @covers ::resizeMulti
270- * @expectedException \InvalidArgumentException
271- * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
272257 */
273258 public function resizeZeroBoxWidth ()
274259 {
260+ $ this ->expectException (\InvalidArgumentException::class);
261+ $ this ->expectExceptionMessage ('a $boxSizes width was not between 0 and $options["maxWidth"] ' );
275262 Image::resize (new \Imagick (), 0 , 10 );
276263 }
277264
278265 /**
279266 * @test
280267 * @covers ::resize
281268 * @covers ::resizeMulti
282- * @expectedException \InvalidArgumentException
283- * @expectedExceptionMessage a $boxSizes width was not between 0 and $options["maxWidth"]
284269 */
285270 public function resizeLargeBoxWidth ()
286271 {
272+ $ this ->expectException (\InvalidArgumentException::class);
273+ $ this ->expectExceptionMessage ('a $boxSizes width was not between 0 and $options["maxWidth"] ' );
287274 Image::resize (new \Imagick (), 10001 , 10 , ['maxWidth ' => 10000 ]);
288275 }
289276
290277 /**
291278 * @test
292279 * @covers ::resize
293280 * @covers ::resizeMulti
294- * @expectedException \InvalidArgumentException
295- * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
296281 */
297282 public function resizeZeroBoxHeight ()
298283 {
284+ $ this ->expectException (\InvalidArgumentException::class);
285+ $ this ->expectExceptionMessage ('a $boxSizes height was not between 0 and $options["maxHeight"] ' );
299286 Image::resize (new \Imagick (), 10 , 0 );
300287 }
301288
302289 /**
303290 * @test
304291 * @covers ::resize
305292 * @covers ::resizeMulti
306- * @expectedException \InvalidArgumentException
307- * @expectedExceptionMessage a $boxSizes height was not between 0 and $options["maxHeight"]
308293 */
309294 public function resizeLargeBoxHeight ()
310295 {
296+ $ this ->expectException (\InvalidArgumentException::class);
297+ $ this ->expectExceptionMessage ('a $boxSizes height was not between 0 and $options["maxHeight"] ' );
311298 Image::resize (new \Imagick (), 10 , 10001 , ['maxHeight ' => 10000 ]);
312299 }
313300
314301 /**
315302 * @test
316303 * @covers ::resize
317304 * @covers ::resizeMulti
318- * @expectedException \InvalidArgumentException
319- * @expectedExceptionMessage $options["color"] was not a string
320305 */
321306 public function resizeNonStringColor ()
322307 {
308+ $ this ->expectException (\InvalidArgumentException::class);
309+ $ this ->expectExceptionMessage ('$options["color"] was not a string ' );
323310 Image::resize (new \Imagick (), 10 , 10 , ['color ' => 0 ]);
324311 }
325312
326313 /**
327314 * @test
328315 * @covers ::resize
329316 * @covers ::resizeMulti
330- * @expectedException \InvalidArgumentException
331- * @expectedExceptionMessage $options["maxWidth"] was not an int
332317 */
333318 public function resizeonIntMaxWidth ()
334319 {
320+ $ this ->expectException (\InvalidArgumentException::class);
321+ $ this ->expectExceptionMessage ('$options["maxWidth"] was not an int ' );
335322 Image::resize (new \Imagick (), 10 , 10 , ['maxWidth ' => 'not int ' ]);
336323 }
337324
338325 /**
339326 * @test
340327 * @covers ::resize
341328 * @covers ::resizeMulti
342- * @expectedException \InvalidArgumentException
343- * @expectedExceptionMessage $options["maxHeight"] was not an int
344329 */
345330 public function resizeNonIntMaxHeight ()
346331 {
332+ $ this ->expectException (\InvalidArgumentException::class);
333+ $ this ->expectExceptionMessage ('$options["maxHeight"] was not an int ' );
347334 Image::resize (new \Imagick (), 10 , 10 , ['maxHeight ' => 'not int ' ]);
348335 }
349336
350337 /**
351338 * @test
352339 * @covers ::resize
353340 * @covers ::resizeMulti
354- * @expectedException \InvalidArgumentException
355- * @expectedExceptionMessage $options["upsize"] was not a bool
356341 */
357342 public function resizeNonBoolUpsize ()
358343 {
344+ $ this ->expectException (\InvalidArgumentException::class);
345+ $ this ->expectExceptionMessage ('$options["upsize"] was not a bool ' );
359346 Image::resize (new \Imagick (), 10 , 10 , ['upsize ' => 'not bool ' ]);
360347 }
361348
362349 /**
363350 * @test
364351 * @covers ::resize
365352 * @covers ::resizeMulti
366- * @expectedException \InvalidArgumentException
367- * @expectedExceptionMessage $options["bestfit"] was not a bool
368353 */
369354 public function resizeNonBoolBestFit ()
370355 {
356+ $ this ->expectException (\InvalidArgumentException::class);
357+ $ this ->expectExceptionMessage ('$options["bestfit"] was not a bool ' );
371358 Image::resize (new \Imagick (), 10 , 10 , ['bestfit ' => 'not bool ' ]);
372359 }
373360
@@ -510,22 +497,22 @@ public function resizeMultiPerformance()
510497 /**
511498 * @test
512499 * @covers ::resizeMulti
513- * @expectedException \InvalidArgumentException
514- * @expectedExceptionMessage a width in a $boxSizes value was not an int
515500 */
516501 public function resizeMultiNonIntWidth ()
517502 {
503+ $ this ->expectException (\InvalidArgumentException::class);
504+ $ this ->expectExceptionMessage ('a width in a $boxSizes value was not an int ' );
518505 Image::resizeMulti (new \Imagick (), [['width ' => true , 'height ' => 10 ]]);
519506 }
520507
521508 /**
522509 * @test
523510 * @covers ::resizeMulti
524- * @expectedException \InvalidArgumentException
525- * @expectedExceptionMessage a height in a $boxSizes value was not an int
526511 */
527512 public function resizeMultiNonIntHeight ()
528513 {
514+ $ this ->expectException (\InvalidArgumentException::class);
515+ $ this ->expectExceptionMessage ('a height in a $boxSizes value was not an int ' );
529516 Image::resizeMulti (new \Imagick (), [['width ' => 10 , 'height ' => true ]]);
530517 }
531518
@@ -621,44 +608,44 @@ public function write()
621608 /**
622609 * @test
623610 * @covers ::write
624- * @expectedException \InvalidArgumentException
625- * @expectedExceptionMessage $options["directoryMode"] was not an int
626611 */
627612 public function writeNonIntDirectoryMode ()
628613 {
614+ $ this ->expectException (\InvalidArgumentException::class);
615+ $ this ->expectExceptionMessage ('$options["directoryMode"] was not an int ' );
629616 Image::write (new \Imagick (), 'not under test ' , ['directoryMode ' => 'not int ' ]);
630617 }
631618
632619 /**
633620 * @test
634621 * @covers ::write
635- * @expectedException \InvalidArgumentException
636- * @expectedExceptionMessage $options["fileMode"] was not an int
637622 */
638623 public function writeNonIntFileMode ()
639624 {
625+ $ this ->expectException (\InvalidArgumentException::class);
626+ $ this ->expectExceptionMessage ('$options["fileMode"] was not an int ' );
640627 Image::write (new \Imagick (), 'not under test ' , ['fileMode ' => 'not int ' ]);
641628 }
642629
643630 /**
644631 * @test
645632 * @covers ::write
646- * @expectedException \InvalidArgumentException
647- * @expectedExceptionMessage $options["format"] was not a string
648633 */
649634 public function writeNonStringFormat ()
650635 {
636+ $ this ->expectException (\InvalidArgumentException::class);
637+ $ this ->expectExceptionMessage ('$options["format"] was not a string ' );
651638 Image::write (new \Imagick (), 'not under test ' , ['format ' => true ]);
652639 }
653640
654641 /**
655642 * @test
656643 * @covers ::write
657- * @expectedException \InvalidArgumentException
658- * @expectedExceptionMessage $options["stripHeaders"] was not a bool
659644 */
660645 public function writeNonBoolStripHeaders ()
661646 {
647+ $ this ->expectException (\InvalidArgumentException::class);
648+ $ this ->expectExceptionMessage ('$options["stripHeaders"] was not a bool ' );
662649 Image::write (new \Imagick (), 'not under test ' , ['stripHeaders ' => 'not bool ' ]);
663650 }
664651
@@ -672,7 +659,10 @@ public function stripHeaders()
672659 {
673660 $ path = "{$ this ->tempDir }/stripHeaders.jpg " ;
674661
675- mkdir ($ this ->tempDir );
662+ if (!file_exists ($ this ->tempDir )) {
663+ mkdir ($ this ->tempDir );
664+ }
665+
676666 copy ("{$ this ->sourceFilesDir }/exif.jpg " , $ path );
677667
678668 Image::stripHeaders ($ path );
@@ -686,10 +676,10 @@ public function stripHeaders()
686676 *
687677 * @test
688678 * @covers ::stripHeaders
689- * @expectedException \ImagickException
690679 */
691680 public function stripHeadersMissingImage ()
692681 {
682+ $ this ->expectException (\ImagickException::class);
693683 Image::stripHeaders ("{$ this ->tempDir }/doesnotexist.jpg " );
694684 }
695685
0 commit comments