encoderByFileExtension($extension); } }; return $encoder->test($extension); } #[DataProvider('targetEncoderProvider')] public function testEncoderByFileExtensionString( string|FileExtension $fileExtension, string $targetEncoderClassname, ): void { $this->assertInstanceOf( $targetEncoderClassname, $this->testEncoder($fileExtension), ); } public static function targetEncoderProvider(): array { return [ ['webp', WebpEncoder::class], ['avif', AvifEncoder::class], ['jpeg', JpegEncoder::class], ['jpg', JpegEncoder::class], ['bmp', BmpEncoder::class], ['gif', GifEncoder::class], ['png', PngEncoder::class], ['tiff', TiffEncoder::class], ['tif', TiffEncoder::class], ['jp2', Jpeg2000Encoder::class], ['heic', HeicEncoder::class], [FileExtension::WEBP, WebpEncoder::class], [FileExtension::AVIF, AvifEncoder::class], [FileExtension::JPG, JpegEncoder::class], [FileExtension::BMP, BmpEncoder::class], [FileExtension::GIF, GifEncoder::class], [FileExtension::PNG, PngEncoder::class], [FileExtension::TIF, TiffEncoder::class], [FileExtension::TIFF, TiffEncoder::class], [FileExtension::JP2, Jpeg2000Encoder::class], [FileExtension::HEIC, HeicEncoder::class], ]; } public function testArgumentsNotSupportedByTargetEncoder(): void { $encoder = $this->testEncoder( 'png', [ 'interlaced' => true, // is not ignored 'quality' => 10, // is ignored because png encoder has no quality argument ], ); $this->assertInstanceOf(PngEncoder::class, $encoder); $this->assertTrue($encoder->interlaced); } public function testEncoderByFileExtensionUnknown(): void { $this->expectException(EncoderException::class); $this->testEncoder('test'); } }