1010namespace Tests \Image ;
1111
1212use Framework \Image \Image ;
13+ use InvalidArgumentException ;
1314use PHPUnit \Framework \TestCase ;
1415use RuntimeException ;
1516
@@ -96,7 +97,7 @@ public function testQualityPng() : void
9697 self ::assertSame (6 , $ this ->image ->getQuality ());
9798 $ this ->image ->setQuality (9 );
9899 self ::assertSame (9 , $ this ->image ->getQuality ());
99- $ this ->expectException (\ InvalidArgumentException::class);
100+ $ this ->expectException (InvalidArgumentException::class);
100101 $ this ->expectExceptionMessage (
101102 'PNG images must receive a quality value between 0 and 9, 75 given '
102103 );
@@ -109,7 +110,7 @@ public function testQualityJpeg() : void
109110 self ::assertSame (75 , $ this ->image ->getQuality ());
110111 $ this ->image ->setQuality (100 );
111112 self ::assertSame (100 , $ this ->image ->getQuality ());
112- $ this ->expectException (\ InvalidArgumentException::class);
113+ $ this ->expectException (InvalidArgumentException::class);
113114 $ this ->expectExceptionMessage (
114115 'JPEG images must receive a quality value between 0 and 100, -1 given '
115116 );
@@ -133,7 +134,7 @@ public function testQualityAvif() : void
133134 self ::assertSame (52 , $ this ->image ->getQuality ());
134135 $ this ->image ->setQuality (90 );
135136 self ::assertSame (90 , $ this ->image ->getQuality ());
136- $ this ->expectException (\ InvalidArgumentException::class);
137+ $ this ->expectException (InvalidArgumentException::class);
137138 $ this ->expectExceptionMessage (
138139 'AVIF images must receive a quality value between 0 and 100, -1 given '
139140 );
@@ -166,7 +167,7 @@ public function testOpacityGreatLevel() : void
166167
167168 public function testOpacityInvalidLevel () : void
168169 {
169- $ this ->expectException (\ InvalidArgumentException::class);
170+ $ this ->expectException (InvalidArgumentException::class);
170171 $ this ->expectExceptionMessage (
171172 'Opacity percentage must be between 0 and 100, 120 given '
172173 );
@@ -229,6 +230,13 @@ public function testFlipBoth() : void
229230 );
230231 }
231232
233+ public function testInvalidFlipDirection () : void
234+ {
235+ $ this ->expectException (InvalidArgumentException::class);
236+ $ this ->expectExceptionMessage ('Invalid image flip direction: foo ' );
237+ $ this ->image ->flip ('foo ' );
238+ }
239+
232240 public function testCrop () : void
233241 {
234242 $ this ->image ->crop (200 , 200 , 100 , 100 );
@@ -285,7 +293,7 @@ public function testToString() : void
285293
286294 public function testFileNotReadable () : void
287295 {
288- $ this ->expectException (\ InvalidArgumentException::class);
296+ $ this ->expectException (InvalidArgumentException::class);
289297 $ this ->expectExceptionMessage ('File does not exists or is not readable: /tmp/foo ' );
290298 new Image ('/tmp/foo ' );
291299 }
@@ -298,28 +306,19 @@ public function testUnsupportedType() : void
298306 new Image ($ file );
299307 }
300308
301- public function testJpgType () : void
302- {
303- $ file = __DIR__ . '/Support/tree.jpg ' ;
304- $ image = new Image ($ file );
305- self ::assertTrue ($ image ->save ());
306- $ image ->render ();
307- }
308-
309- public function testGifType () : void
309+ /**
310+ * @dataProvider imageTypesProvider
311+ *
312+ * @param string $extension
313+ */
314+ public function testTypes (string $ extension ) : void
310315 {
311- $ file = __DIR__ . '/Support/tree.gif ' ;
312- $ image = new Image ($ file );
313- self ::assertTrue ($ image ->save ());
314- $ image ->render ();
315- }
316-
317- public function testAvifType () : void
318- {
319- $ file = __DIR__ . '/Support/tree.avif ' ;
320- $ image = new Image ($ file );
316+ $ filename = __DIR__ . '/Support/tree ' . $ extension ;
317+ $ backup = \file_get_contents ($ filename );
318+ $ image = new Image ($ filename );
321319 self ::assertTrue ($ image ->save ());
322320 $ image ->render ();
321+ \file_put_contents ($ filename , $ backup );
323322 }
324323
325324 public function testCreate () : void
@@ -342,4 +341,17 @@ public function testCreate() : void
342341 $ this ->expectExceptionMessage ('Image could not be created ' );
343342 $ this ->image ->create ('foo ' , $ filename );
344343 }
344+
345+ /**
346+ * @return array<array<string>>
347+ */
348+ public static function imageTypesProvider () : array
349+ {
350+ return [
351+ ['.png ' ],
352+ ['.jpg ' ],
353+ ['.gif ' ],
354+ ['.avif ' ],
355+ ];
356+ }
345357}
0 commit comments