From b496d1f6b9f812f96166623358dfcafb8c3b1683 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 27 Oct 2024 11:15:54 +0100 Subject: [PATCH] Add test assertions to validate the correct mime type --- tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php | 1 + tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php | 1 + tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php | 3 +++ tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php | 2 ++ tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php | 2 ++ tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php | 3 +++ tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php | 2 ++ tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php | 2 ++ tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php | 1 + tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php | 1 + 15 files changed, 23 insertions(+) diff --git a/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php index b2e5d828..1419d54c 100644 --- a/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/AvifEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new AvifEncoder(10); $result = $encoder->encode($image); $this->assertMediaType('image/avif', $result); + $this->assertEquals('image/avif', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php index 27fb805e..25a0d638 100644 --- a/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/BmpEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new BmpEncoder(); $result = $encoder->encode($image); $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); + $this->assertEquals('image/bmp', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php index d3ddc342..6a87d7c5 100644 --- a/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php @@ -21,6 +21,7 @@ public function testEncode(): void $encoder = new GifEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertFalse( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); @@ -32,6 +33,7 @@ public function testEncodeInterlaced(): void $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); @@ -43,6 +45,7 @@ public function testEncodeInterlacedAnimation(): void $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); diff --git a/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php index bb428c06..5e29fcc8 100644 --- a/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/JpegEncoderTest.php @@ -23,6 +23,7 @@ public function testEncode(): void $encoder = new JpegEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); + $this->assertEquals('image/jpeg', $result->mimetype()); } public function testEncodeProgressive(): void @@ -31,6 +32,7 @@ public function testEncodeProgressive(): void $encoder = new JpegEncoder(progressive: true); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); + $this->assertEquals('image/jpeg', $result->mimetype()); $this->assertTrue($this->isProgressiveJpeg($result)); } } diff --git a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php index 5f55f7df..fe5358cb 100644 --- a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php @@ -25,6 +25,7 @@ public function testEncode(): void $encoder = new PngEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); + $this->assertEquals('image/png', $result->mimetype()); $this->assertFalse($this->isInterlacedPng($result)); } @@ -34,6 +35,7 @@ public function testEncodeInterlaced(): void $encoder = new PngEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); + $this->assertEquals('image/png', $result->mimetype()); $this->assertTrue($this->isInterlacedPng($result)); } diff --git a/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php index c6874678..c65a12fa 100644 --- a/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/WebpEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new WebpEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/webp', $result); + $this->assertEquals('image/webp', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php index 64650c18..b425a2f3 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/AvifEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new AvifEncoder(10); $result = $encoder->encode($image); $this->assertMediaType('image/avif', $result); + $this->assertEquals('image/avif', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php index 8e465b66..2ac9f962 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/BmpEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new BmpEncoder(); $result = $encoder->encode($image); $this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], $result); + $this->assertEquals('image/bmp', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php index f56b0153..7085f95b 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php @@ -21,6 +21,7 @@ public function testEncode(): void $encoder = new GifEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertFalse( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); @@ -32,6 +33,7 @@ public function testEncodeInterlaced(): void $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); @@ -43,6 +45,7 @@ public function testEncodeInterlacedAnimation(): void $encoder = new GifEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/gif', $result); + $this->assertEquals('image/gif', $result->mimetype()); $this->assertTrue( Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced() ); diff --git a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php index 759c8fe1..b3843dad 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/HeicEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new HeicEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/heic', $result); + $this->assertEquals('image/heic', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php index 398b5bbc..689604a4 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/Jpeg2000EncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new Jpeg2000Encoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/jp2', $result); + $this->assertEquals('image/jp2', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php index 4bf7bedd..79285fc6 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/JpegEncoderTest.php @@ -23,6 +23,7 @@ public function testEncode(): void $encoder = new JpegEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); + $this->assertEquals('image/jpeg', $result->mimetype()); } public function testEncodeProgressive(): void @@ -31,6 +32,7 @@ public function testEncodeProgressive(): void $encoder = new JpegEncoder(progressive: true); $result = $encoder->encode($image); $this->assertMediaType('image/jpeg', $result); + $this->assertEquals('image/jpeg', $result->mimetype()); $this->assertTrue($this->isProgressiveJpeg($result)); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php index c5cb4c22..5684bb1c 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php @@ -25,6 +25,7 @@ public function testEncode(): void $encoder = new PngEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); + $this->assertEquals('image/png', $result->mimetype()); $this->assertFalse($this->isInterlacedPng($result)); } @@ -34,6 +35,7 @@ public function testEncodeInterlaced(): void $encoder = new PngEncoder(interlaced: true); $result = $encoder->encode($image); $this->assertMediaType('image/png', $result); + $this->assertEquals('image/png', $result->mimetype()); $this->assertTrue($this->isInterlacedPng($result)); } diff --git a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php index 7f2e4c3c..25cf769c 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/TiffEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new TiffEncoder(); $result = $encoder->encode($image); $this->assertMediaType('image/tiff', $result); + $this->assertEquals('image/tiff', $result->mimetype()); } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php index 48c3e312..89f3b39f 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/WebpEncoderTest.php @@ -20,5 +20,6 @@ public function testEncode(): void $encoder = new WebpEncoder(75); $result = $encoder->encode($image); $this->assertMediaType('image/webp', $result); + $this->assertEquals('image/webp', $result->mimetype()); } }