diff --git a/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php index 9eda0ef2..b7d2da5c 100644 --- a/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php +++ b/tests/Unit/Colors/Hsl/Decoders/StringColorDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Colors\Hsl\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Hsl\Color; @@ -24,29 +25,27 @@ public function testDecode(string $input, string $classname, array $channelValue $this->assertEquals($channelValues, $result->toArray()); } - public static function decodeDataProvier(): array + public static function decodeDataProvier(): Generator { - return [ - [ - 'hsl(0,0,0)', - Color::class, - [0, 0, 0], - ], - [ - 'hsl(0, 100, 50)', - Color::class, - [0, 100, 50], - ], - [ - 'hsl(360, 100, 50)', - Color::class, - [360, 100, 50], - ], - [ - 'hsl(180, 100%, 50%)', - Color::class, - [180, 100, 50], - ] + yield [ + 'hsl(0,0,0)', + Color::class, + [0, 0, 0], + ]; + yield [ + 'hsl(0, 100, 50)', + Color::class, + [0, 100, 50], + ]; + yield [ + 'hsl(360, 100, 50)', + Color::class, + [360, 100, 50], + ]; + yield [ + 'hsl(180, 100%, 50%)', + Color::class, + [180, 100, 50], ]; } } diff --git a/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php index 8b146d28..1500d882 100644 --- a/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php +++ b/tests/Unit/Colors/Hsv/Decoders/StringColorDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Colors\Hsv\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Hsv\Color; @@ -24,49 +25,47 @@ public function testDecodeHsv(string $input, string $classname, array $channelVa $this->assertEquals($channelValues, $result->toArray()); } - public static function decodeDataProvier(): array + public static function decodeDataProvier(): Generator { - return [ - [ - 'hsv(0,0,0)', - Color::class, - [0, 0, 0], - ], - [ - 'hsv(0, 100, 100)', - Color::class, - [0, 100, 100], - ], - [ - 'hsv(360, 100, 100)', - Color::class, - [360, 100, 100], - ], - [ - 'hsv(180, 100%, 100%)', - Color::class, - [180, 100, 100], - ], - [ - 'hsb(0,0,0)', - Color::class, - [0, 0, 0], - ], - [ - 'hsb(0, 100, 100)', - Color::class, - [0, 100, 100], - ], - [ - 'hsb(360, 100, 100)', - Color::class, - [360, 100, 100], - ], - [ - 'hsb(180, 100%, 100%)', - Color::class, - [180, 100, 100], - ], + yield [ + 'hsv(0,0,0)', + Color::class, + [0, 0, 0], + ]; + yield [ + 'hsv(0, 100, 100)', + Color::class, + [0, 100, 100], + ]; + yield [ + 'hsv(360, 100, 100)', + Color::class, + [360, 100, 100], + ]; + yield [ + 'hsv(180, 100%, 100%)', + Color::class, + [180, 100, 100], + ]; + yield [ + 'hsb(0,0,0)', + Color::class, + [0, 0, 0], + ]; + yield [ + 'hsb(0, 100, 100)', + Color::class, + [0, 100, 100], + ]; + yield [ + 'hsb(360, 100, 100)', + Color::class, + [360, 100, 100], + ]; + yield [ + 'hsb(180, 100%, 100%)', + Color::class, + [180, 100, 100], ]; } } diff --git a/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php index fbe13779..f4cd8354 100644 --- a/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php +++ b/tests/Unit/Colors/Rgb/Decoders/HexColorDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Rgb\Color; @@ -24,59 +25,57 @@ public function testDecode(string $input, string $classname, array $channelValue $this->assertEquals($channelValues, $result->toArray()); } - public static function decodeDataProvier(): array + public static function decodeDataProvier(): Generator { - return [ - [ - 'ccc', - Color::class, - [204, 204, 204, 255] - ], - [ - 'ccff33', - Color::class, - [204, 255, 51, 255], - ], - [ - '#ccc', - Color::class, - [204, 204, 204, 255], - ], - [ - 'cccccc', - Color::class, - [204, 204, 204, 255], - ], - [ - '#cccccc', - Color::class, - [204, 204, 204, 255], - ], - [ - '#ccccccff', - Color::class, - [204, 204, 204, 255], - ], - [ - '#cccf', - Color::class, - [204, 204, 204, 255], - ], - [ - 'ccccccff', - Color::class, - [204, 204, 204, 255], - ], - [ - 'cccf', - Color::class, - [204, 204, 204, 255], - ], - [ - '#b53717aa', - Color::class, - [181, 55, 23, 170], - ], + yield [ + 'ccc', + Color::class, + [204, 204, 204, 255] + ]; + yield [ + 'ccff33', + Color::class, + [204, 255, 51, 255], + ]; + yield [ + '#ccc', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'cccccc', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + '#cccccc', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + '#ccccccff', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + '#cccf', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'ccccccff', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'cccf', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + '#b53717aa', + Color::class, + [181, 55, 23, 170], ]; } } diff --git a/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php index afe418e0..e6b84029 100644 --- a/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php +++ b/tests/Unit/Colors/Rgb/Decoders/HtmlColornameDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Rgb\Color; @@ -24,24 +25,22 @@ public function testDecode(string $input, string $classname, array $channelValue $this->assertEquals($channelValues, $result->toArray()); } - public static function decodeDataProvier(): array + public static function decodeDataProvier(): Generator { - return [ - [ - 'salmon', - Color::class, - [250, 128, 114, 255], - ], - [ - 'khaki', - Color::class, - [240, 230, 140, 255], - ], - [ - 'peachpuff', - Color::class, - [255, 218, 185, 255], - ] + yield [ + 'salmon', + Color::class, + [250, 128, 114, 255], + ]; + yield [ + 'khaki', + Color::class, + [240, 230, 140, 255], + ]; + yield [ + 'peachpuff', + Color::class, + [255, 218, 185, 255], ]; } } diff --git a/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php b/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php index bf135325..5f6503f1 100644 --- a/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php +++ b/tests/Unit/Colors/Rgb/Decoders/StringColorDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Colors\Rgb\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Colors\Rgb\Color; @@ -24,49 +25,47 @@ public function testDecode(string $input, string $classname, array $channelValue $this->assertEquals($channelValues, $result->toArray()); } - public static function decodeDataProvier(): array + public static function decodeDataProvier(): Generator { - return [ - [ - 'rgb(204, 204, 204)', - Color::class, - [204, 204, 204, 255], - ], - [ - 'rgb(204,204,204)', - Color::class, - [204, 204, 204, 255], - ], - [ - 'rgb(100%,20%,0%)', - Color::class, - [255, 51, 0, 255], - ], - [ - 'rgb(100%,19.8064%,0.1239483%)', - Color::class, - [255, 51, 0, 255], - ], - [ - 'rgba(204, 204, 204, 1)', - Color::class, - [204, 204, 204, 255], - ], - [ - 'rgba(204,204,204,.2)', - Color::class, - [204, 204, 204, 51], - ], - [ - 'rgba(204,204,204,0.2)', - Color::class, - [204, 204, 204, 51], - ], - [ - 'srgb(255, 0, 0)', - Color::class, - [255, 0, 0, 255], - ], + yield [ + 'rgb(204, 204, 204)', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'rgb(204,204,204)', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'rgb(100%,20%,0%)', + Color::class, + [255, 51, 0, 255], + ]; + yield [ + 'rgb(100%,19.8064%,0.1239483%)', + Color::class, + [255, 51, 0, 255], + ]; + yield [ + 'rgba(204, 204, 204, 1)', + Color::class, + [204, 204, 204, 255], + ]; + yield [ + 'rgba(204,204,204,.2)', + Color::class, + [204, 204, 204, 51], + ]; + yield [ + 'rgba(204,204,204,0.2)', + Color::class, + [204, 204, 204, 51], + ]; + yield [ + 'srgb(255, 0, 0)', + Color::class, + [255, 0, 0, 255], ]; } } diff --git a/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php b/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php index 9a76bd2f..e17ebf46 100644 --- a/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php +++ b/tests/Unit/Drivers/Gd/Decoders/FilePathImageDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Gd\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Gd\Decoders\FilePathImageDecoder; @@ -39,18 +40,16 @@ public function testDecode(string $path, bool $result): void } } - public static function validFormatPathsProvider(): array + public static function validFormatPathsProvider(): Generator { - return [ - [self::getTestResourcePath('cats.gif'), true], - [self::getTestResourcePath('animation.gif'), true], - [self::getTestResourcePath('red.gif'), true], - [self::getTestResourcePath('green.gif'), true], - [self::getTestResourcePath('blue.gif'), true], - [self::getTestResourcePath('gradient.bmp'), true], - [self::getTestResourcePath('circle.png'), true], - ['no-path', false], - [str_repeat('x', PHP_MAXPATHLEN + 1), false], - ]; + yield [self::getTestResourcePath('cats.gif'), true]; + yield [self::getTestResourcePath('animation.gif'), true]; + yield [self::getTestResourcePath('red.gif'), true]; + yield [self::getTestResourcePath('green.gif'), true]; + yield [self::getTestResourcePath('blue.gif'), true]; + yield [self::getTestResourcePath('gradient.bmp'), true]; + yield [self::getTestResourcePath('circle.png'), true]; + yield ['no-path', false]; + yield [str_repeat('x', PHP_MAXPATHLEN + 1), false]; } } diff --git a/tests/Unit/Drivers/Gd/DriverTest.php b/tests/Unit/Drivers/Gd/DriverTest.php index 3ba81e1e..989e3cad 100644 --- a/tests/Unit/Drivers/Gd/DriverTest.php +++ b/tests/Unit/Drivers/Gd/DriverTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Gd; +use Generator; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Drivers\Gd\Driver; @@ -92,115 +93,113 @@ public function testSupports(bool $result, mixed $identifier): void $this->assertEquals($result, $this->driver->supports($identifier)); } - public static function supportsDataProvider(): array + public static function supportsDataProvider(): Generator { - return [ - [true, Format::JPEG], - [true, MediaType::IMAGE_JPEG], - [true, MediaType::IMAGE_JPG], - [true, FileExtension::JPG], - [true, FileExtension::JPEG], - [true, 'jpg'], - [true, 'jpeg'], - [true, 'image/jpg'], - [true, 'image/jpeg'], - - [true, Format::WEBP], - [true, MediaType::IMAGE_WEBP], - [true, MediaType::IMAGE_X_WEBP], - [true, FileExtension::WEBP], - [true, 'webp'], - [true, 'image/webp'], - [true, 'image/x-webp'], - - [true, Format::GIF], - [true, MediaType::IMAGE_GIF], - [true, FileExtension::GIF], - [true, 'gif'], - [true, 'image/gif'], - - [true, Format::PNG], - [true, MediaType::IMAGE_PNG], - [true, MediaType::IMAGE_X_PNG], - [true, FileExtension::PNG], - [true, 'png'], - [true, 'image/png'], - [true, 'image/x-png'], - - [true, Format::AVIF], - [true, MediaType::IMAGE_AVIF], - [true, MediaType::IMAGE_X_AVIF], - [true, FileExtension::AVIF], - [true, 'avif'], - [true, 'image/avif'], - [true, 'image/x-avif'], - - [true, Format::BMP], - [true, FileExtension::BMP], - [true, MediaType::IMAGE_BMP], - [true, MediaType::IMAGE_MS_BMP], - [true, MediaType::IMAGE_X_BITMAP], - [true, MediaType::IMAGE_X_BMP], - [true, MediaType::IMAGE_X_MS_BMP], - [true, MediaType::IMAGE_X_WINDOWS_BMP], - [true, MediaType::IMAGE_X_WIN_BITMAP], - [true, MediaType::IMAGE_X_XBITMAP], - [true, 'bmp'], - [true, 'image/bmp'], - [true, 'image/ms-bmp'], - [true, 'image/x-bitmap'], - [true, 'image/x-bmp'], - [true, 'image/x-ms-bmp'], - [true, 'image/x-windows-bmp'], - [true, 'image/x-win-bitmap'], - [true, 'image/x-xbitmap'], - - [false, Format::TIFF], - [false, MediaType::IMAGE_TIFF], - [false, FileExtension::TIFF], - [false, FileExtension::TIF], - [false, 'tif'], - [false, 'tiff'], - [false, 'image/tiff'], - - [false, Format::JP2], - [false, MediaType::IMAGE_JP2], - [false, MediaType::IMAGE_JPX], - [false, MediaType::IMAGE_JPM], - [false, FileExtension::TIFF], - [false, FileExtension::TIF], - [false, FileExtension::JP2], - [false, FileExtension::J2K], - [false, FileExtension::JPF], - [false, FileExtension::JPM], - [false, FileExtension::JPG2], - [false, FileExtension::J2C], - [false, FileExtension::JPC], - [false, FileExtension::JPX], - [false, 'jp2'], - [false, 'j2k'], - [false, 'jpf'], - [false, 'jpm'], - [false, 'jpg2'], - [false, 'j2c'], - [false, 'jpc'], - [false, 'jpx'], - - [false, Format::HEIC], - [false, MediaType::IMAGE_HEIC], - [false, MediaType::IMAGE_HEIF], - [false, FileExtension::HEIC], - [false, FileExtension::HEIF], - [false, 'heic'], - [false, 'heif'], - [false, 'image/heic'], - [false, 'image/heif'], - - [false, 'tga'], - [false, 'image/tga'], - [false, 'image/x-targa'], - [false, 'foo'], - [false, ''], - ]; + yield [true, Format::JPEG]; + yield [true, MediaType::IMAGE_JPEG]; + yield [true, MediaType::IMAGE_JPG]; + yield [true, FileExtension::JPG]; + yield [true, FileExtension::JPEG]; + yield [true, 'jpg']; + yield [true, 'jpeg']; + yield [true, 'image/jpg']; + yield [true, 'image/jpeg']; + + yield [true, Format::WEBP]; + yield [true, MediaType::IMAGE_WEBP]; + yield [true, MediaType::IMAGE_X_WEBP]; + yield [true, FileExtension::WEBP]; + yield [true, 'webp']; + yield [true, 'image/webp']; + yield [true, 'image/x-webp']; + + yield [true, Format::GIF]; + yield [true, MediaType::IMAGE_GIF]; + yield [true, FileExtension::GIF]; + yield [true, 'gif']; + yield [true, 'image/gif']; + + yield [true, Format::PNG]; + yield [true, MediaType::IMAGE_PNG]; + yield [true, MediaType::IMAGE_X_PNG]; + yield [true, FileExtension::PNG]; + yield [true, 'png']; + yield [true, 'image/png']; + yield [true, 'image/x-png']; + + yield [true, Format::AVIF]; + yield [true, MediaType::IMAGE_AVIF]; + yield [true, MediaType::IMAGE_X_AVIF]; + yield [true, FileExtension::AVIF]; + yield [true, 'avif']; + yield [true, 'image/avif']; + yield [true, 'image/x-avif']; + + yield [true, Format::BMP]; + yield [true, FileExtension::BMP]; + yield [true, MediaType::IMAGE_BMP]; + yield [true, MediaType::IMAGE_MS_BMP]; + yield [true, MediaType::IMAGE_X_BITMAP]; + yield [true, MediaType::IMAGE_X_BMP]; + yield [true, MediaType::IMAGE_X_MS_BMP]; + yield [true, MediaType::IMAGE_X_WINDOWS_BMP]; + yield [true, MediaType::IMAGE_X_WIN_BITMAP]; + yield [true, MediaType::IMAGE_X_XBITMAP]; + yield [true, 'bmp']; + yield [true, 'image/bmp']; + yield [true, 'image/ms-bmp']; + yield [true, 'image/x-bitmap']; + yield [true, 'image/x-bmp']; + yield [true, 'image/x-ms-bmp']; + yield [true, 'image/x-windows-bmp']; + yield [true, 'image/x-win-bitmap']; + yield [true, 'image/x-xbitmap']; + + yield [false, Format::TIFF]; + yield [false, MediaType::IMAGE_TIFF]; + yield [false, FileExtension::TIFF]; + yield [false, FileExtension::TIF]; + yield [false, 'tif']; + yield [false, 'tiff']; + yield [false, 'image/tiff']; + + yield [false, Format::JP2]; + yield [false, MediaType::IMAGE_JP2]; + yield [false, MediaType::IMAGE_JPX]; + yield [false, MediaType::IMAGE_JPM]; + yield [false, FileExtension::TIFF]; + yield [false, FileExtension::TIF]; + yield [false, FileExtension::JP2]; + yield [false, FileExtension::J2K]; + yield [false, FileExtension::JPF]; + yield [false, FileExtension::JPM]; + yield [false, FileExtension::JPG2]; + yield [false, FileExtension::J2C]; + yield [false, FileExtension::JPC]; + yield [false, FileExtension::JPX]; + yield [false, 'jp2']; + yield [false, 'j2k']; + yield [false, 'jpf']; + yield [false, 'jpm']; + yield [false, 'jpg2']; + yield [false, 'j2c']; + yield [false, 'jpc']; + yield [false, 'jpx']; + + yield [false, Format::HEIC]; + yield [false, MediaType::IMAGE_HEIC]; + yield [false, MediaType::IMAGE_HEIF]; + yield [false, FileExtension::HEIC]; + yield [false, FileExtension::HEIF]; + yield [false, 'heic']; + yield [false, 'heif']; + yield [false, 'image/heic']; + yield [false, 'image/heif']; + + yield [false, 'tga']; + yield [false, 'image/tga']; + yield [false, 'image/x-targa']; + yield [false, 'foo']; + yield [false, '']; } } diff --git a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php index fe5358cb..b658696e 100644 --- a/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php +++ b/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Encoders\PngEncoder; @@ -48,49 +49,47 @@ public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, s ); } - public static function indexedDataProvider(): array + public static function indexedDataProvider(): Generator { - return [ - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('circle.png'), // truecolor-alpha - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('circle.png'), // indexedcolor-alpha - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: true), - 'indexed', - ], + yield [ + static::createTestImage(3, 2), // new + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::createTestImage(3, 2), // new + new PngEncoder(indexed: true), + 'indexed', + ]; + yield [ + static::readTestImage('circle.png'), // truecolor-alpha + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('circle.png'), // indexedcolor-alpha + new PngEncoder(indexed: true), + 'indexed', + ]; + yield [ + static::readTestImage('tile.png'), // indexed + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('tile.png'), // indexed + new PngEncoder(indexed: true), + 'indexed', + ]; + yield [ + static::readTestImage('test.jpg'), // jpeg + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('test.jpg'), // jpeg + new PngEncoder(indexed: true), + 'indexed', ]; } } diff --git a/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php b/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php index 8e5cd768..e9b6c528 100644 --- a/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php +++ b/tests/Unit/Drivers/Imagick/Decoders/FilePathImageDecoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Decoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Drivers\Imagick\Decoders\FilePathImageDecoder; @@ -39,18 +40,16 @@ public function testDecode(string $path, bool $result): void } } - public static function validFormatPathsProvider(): array + public static function validFormatPathsProvider(): Generator { - return [ - [self::getTestResourcePath('cats.gif'), true], - [self::getTestResourcePath('animation.gif'), true], - [self::getTestResourcePath('red.gif'), true], - [self::getTestResourcePath('green.gif'), true], - [self::getTestResourcePath('blue.gif'), true], - [self::getTestResourcePath('gradient.bmp'), true], - [self::getTestResourcePath('circle.png'), true], - ['no-path', false], - [str_repeat('x', PHP_MAXPATHLEN + 1), false], - ]; + yield [self::getTestResourcePath('cats.gif'), true]; + yield [self::getTestResourcePath('animation.gif'), true]; + yield [self::getTestResourcePath('red.gif'), true]; + yield [self::getTestResourcePath('green.gif'), true]; + yield [self::getTestResourcePath('blue.gif'), true]; + yield [self::getTestResourcePath('gradient.bmp'), true]; + yield [self::getTestResourcePath('circle.png'), true]; + yield ['no-path', false]; + yield [str_repeat('x', PHP_MAXPATHLEN + 1), false]; } } diff --git a/tests/Unit/Drivers/Imagick/DriverTest.php b/tests/Unit/Drivers/Imagick/DriverTest.php index 93bfd7ae..58d59d98 100644 --- a/tests/Unit/Drivers/Imagick/DriverTest.php +++ b/tests/Unit/Drivers/Imagick/DriverTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick; +use Generator; use Intervention\Image\Colors\Rgb\Colorspace; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Drivers\Imagick\Driver; @@ -92,115 +93,113 @@ public function testSupports(bool $result, mixed $identifier): void $this->assertEquals($result, $this->driver->supports($identifier)); } - public static function supportsDataProvider(): array + public static function supportsDataProvider(): Generator { - return [ - [true, Format::JPEG], - [true, MediaType::IMAGE_JPEG], - [true, MediaType::IMAGE_JPG], - [true, FileExtension::JPG], - [true, FileExtension::JPEG], - [true, 'jpg'], - [true, 'jpeg'], - [true, 'image/jpg'], - [true, 'image/jpeg'], - - [true, Format::WEBP], - [true, MediaType::IMAGE_WEBP], - [true, MediaType::IMAGE_X_WEBP], - [true, FileExtension::WEBP], - [true, 'webp'], - [true, 'image/webp'], - [true, 'image/x-webp'], - - [true, Format::GIF], - [true, MediaType::IMAGE_GIF], - [true, FileExtension::GIF], - [true, 'gif'], - [true, 'image/gif'], - - [true, Format::PNG], - [true, MediaType::IMAGE_PNG], - [true, MediaType::IMAGE_X_PNG], - [true, FileExtension::PNG], - [true, 'png'], - [true, 'image/png'], - [true, 'image/x-png'], - - [true, Format::AVIF], - [true, MediaType::IMAGE_AVIF], - [true, MediaType::IMAGE_X_AVIF], - [true, FileExtension::AVIF], - [true, 'avif'], - [true, 'image/avif'], - [true, 'image/x-avif'], - - [true, Format::BMP], - [true, FileExtension::BMP], - [true, MediaType::IMAGE_BMP], - [true, MediaType::IMAGE_MS_BMP], - [true, MediaType::IMAGE_X_BITMAP], - [true, MediaType::IMAGE_X_BMP], - [true, MediaType::IMAGE_X_MS_BMP], - [true, MediaType::IMAGE_X_WINDOWS_BMP], - [true, MediaType::IMAGE_X_WIN_BITMAP], - [true, MediaType::IMAGE_X_XBITMAP], - [true, 'bmp'], - [true, 'image/bmp'], - [true, 'image/ms-bmp'], - [true, 'image/x-bitmap'], - [true, 'image/x-bmp'], - [true, 'image/x-ms-bmp'], - [true, 'image/x-windows-bmp'], - [true, 'image/x-win-bitmap'], - [true, 'image/x-xbitmap'], - - [true, Format::TIFF], - [true, MediaType::IMAGE_TIFF], - [true, FileExtension::TIFF], - [true, FileExtension::TIF], - [true, 'tif'], - [true, 'tiff'], - [true, 'image/tiff'], - - [true, Format::JP2], - [true, MediaType::IMAGE_JP2], - [true, MediaType::IMAGE_JPX], - [true, MediaType::IMAGE_JPM], - [true, FileExtension::TIFF], - [true, FileExtension::TIF], - [true, FileExtension::JP2], - [true, FileExtension::J2K], - [true, FileExtension::JPF], - [true, FileExtension::JPM], - [true, FileExtension::JPG2], - [true, FileExtension::J2C], - [true, FileExtension::JPC], - [true, FileExtension::JPX], - [true, 'jp2'], - [true, 'j2k'], - [true, 'jpf'], - [true, 'jpm'], - [true, 'jpg2'], - [true, 'j2c'], - [true, 'jpc'], - [true, 'jpx'], - - [true, Format::HEIC], - [true, MediaType::IMAGE_HEIC], - [true, MediaType::IMAGE_HEIF], - [true, FileExtension::HEIC], - [true, FileExtension::HEIF], - [true, 'heic'], - [true, 'heif'], - [true, 'image/heic'], - [true, 'image/heif'], - - [false, 'tga'], - [false, 'image/tga'], - [false, 'image/x-targa'], - [false, 'foo'], - [false, ''], - ]; + yield [true, Format::JPEG]; + yield [true, MediaType::IMAGE_JPEG]; + yield [true, MediaType::IMAGE_JPG]; + yield [true, FileExtension::JPG]; + yield [true, FileExtension::JPEG]; + yield [true, 'jpg']; + yield [true, 'jpeg']; + yield [true, 'image/jpg']; + yield [true, 'image/jpeg']; + + yield [true, Format::WEBP]; + yield [true, MediaType::IMAGE_WEBP]; + yield [true, MediaType::IMAGE_X_WEBP]; + yield [true, FileExtension::WEBP]; + yield [true, 'webp']; + yield [true, 'image/webp']; + yield [true, 'image/x-webp']; + + yield [true, Format::GIF]; + yield [true, MediaType::IMAGE_GIF]; + yield [true, FileExtension::GIF]; + yield [true, 'gif']; + yield [true, 'image/gif']; + + yield [true, Format::PNG]; + yield [true, MediaType::IMAGE_PNG]; + yield [true, MediaType::IMAGE_X_PNG]; + yield [true, FileExtension::PNG]; + yield [true, 'png']; + yield [true, 'image/png']; + yield [true, 'image/x-png']; + + yield [true, Format::AVIF]; + yield [true, MediaType::IMAGE_AVIF]; + yield [true, MediaType::IMAGE_X_AVIF]; + yield [true, FileExtension::AVIF]; + yield [true, 'avif']; + yield [true, 'image/avif']; + yield [true, 'image/x-avif']; + + yield [true, Format::BMP]; + yield [true, FileExtension::BMP]; + yield [true, MediaType::IMAGE_BMP]; + yield [true, MediaType::IMAGE_MS_BMP]; + yield [true, MediaType::IMAGE_X_BITMAP]; + yield [true, MediaType::IMAGE_X_BMP]; + yield [true, MediaType::IMAGE_X_MS_BMP]; + yield [true, MediaType::IMAGE_X_WINDOWS_BMP]; + yield [true, MediaType::IMAGE_X_WIN_BITMAP]; + yield [true, MediaType::IMAGE_X_XBITMAP]; + yield [true, 'bmp']; + yield [true, 'image/bmp']; + yield [true, 'image/ms-bmp']; + yield [true, 'image/x-bitmap']; + yield [true, 'image/x-bmp']; + yield [true, 'image/x-ms-bmp']; + yield [true, 'image/x-windows-bmp']; + yield [true, 'image/x-win-bitmap']; + yield [true, 'image/x-xbitmap']; + + yield [true, Format::TIFF]; + yield [true, MediaType::IMAGE_TIFF]; + yield [true, FileExtension::TIFF]; + yield [true, FileExtension::TIF]; + yield [true, 'tif']; + yield [true, 'tiff']; + yield [true, 'image/tiff']; + + yield [true, Format::JP2]; + yield [true, MediaType::IMAGE_JP2]; + yield [true, MediaType::IMAGE_JPX]; + yield [true, MediaType::IMAGE_JPM]; + yield [true, FileExtension::TIFF]; + yield [true, FileExtension::TIF]; + yield [true, FileExtension::JP2]; + yield [true, FileExtension::J2K]; + yield [true, FileExtension::JPF]; + yield [true, FileExtension::JPM]; + yield [true, FileExtension::JPG2]; + yield [true, FileExtension::J2C]; + yield [true, FileExtension::JPC]; + yield [true, FileExtension::JPX]; + yield [true, 'jp2']; + yield [true, 'j2k']; + yield [true, 'jpf']; + yield [true, 'jpm']; + yield [true, 'jpg2']; + yield [true, 'j2c']; + yield [true, 'jpc']; + yield [true, 'jpx']; + + yield [true, Format::HEIC]; + yield [true, MediaType::IMAGE_HEIC]; + yield [true, MediaType::IMAGE_HEIF]; + yield [true, FileExtension::HEIC]; + yield [true, FileExtension::HEIF]; + yield [true, 'heic']; + yield [true, 'heif']; + yield [true, 'image/heic']; + yield [true, 'image/heif']; + + yield [false, 'tga']; + yield [false, 'image/tga']; + yield [false, 'image/x-targa']; + yield [false, 'foo']; + yield [false, '']; } } diff --git a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php b/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php index 5684bb1c..cf237e80 100644 --- a/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php +++ b/tests/Unit/Drivers/Imagick/Encoders/PngEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use Intervention\Image\Encoders\PngEncoder; @@ -48,55 +49,53 @@ public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, s ); } - public static function indexedDataProvider(): array + public static function indexedDataProvider(): Generator { - return [ - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::createTestImage(3, 2), // new - new PngEncoder(indexed: true), - 'indexed', - ], + yield [ + static::createTestImage(3, 2), // new + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::createTestImage(3, 2), // new + new PngEncoder(indexed: true), + 'indexed', + ]; - [ - static::createTestImage(3, 2)->fill('ccc'), // new grayscale - new PngEncoder(indexed: true), - 'grayscale', // result should be 'indexed' but there seems to be no way to force this with imagick - ], - [ - static::readTestImage('circle.png'), // truecolor-alpha - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('circle.png'), // indexedcolor-alpha - new PngEncoder(indexed: true), - 'grayscale-alpha', // result should be 'indexed' but there seems to be no way to force this with imagick - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('tile.png'), // indexed - new PngEncoder(indexed: true), - 'indexed', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: false), - 'truecolor-alpha', - ], - [ - static::readTestImage('test.jpg'), // jpeg - new PngEncoder(indexed: true), - 'indexed', - ], + yield [ + static::createTestImage(3, 2)->fill('ccc'), // new grayscale + new PngEncoder(indexed: true), + 'grayscale', // result should be 'indexed' but there seems to be no way to force this with imagick + ]; + yield [ + static::readTestImage('circle.png'), // truecolor-alpha + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('circle.png'), // indexedcolor-alpha + new PngEncoder(indexed: true), + 'grayscale-alpha', // result should be 'indexed' but there seems to be no way to force this with imagick + ]; + yield [ + static::readTestImage('tile.png'), // indexed + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('tile.png'), // indexed + new PngEncoder(indexed: true), + 'indexed', + ]; + yield [ + static::readTestImage('test.jpg'), // jpeg + new PngEncoder(indexed: false), + 'truecolor-alpha', + ]; + yield [ + static::readTestImage('test.jpg'), // jpeg + new PngEncoder(indexed: true), + 'indexed', ]; } } diff --git a/tests/Unit/Encoders/FileExtensionEncoderTest.php b/tests/Unit/Encoders/FileExtensionEncoderTest.php index 4e28d9fc..429f117b 100644 --- a/tests/Unit/Encoders/FileExtensionEncoderTest.php +++ b/tests/Unit/Encoders/FileExtensionEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Encoders; +use Generator; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\FileExtensionEncoder; @@ -51,31 +52,29 @@ public function testEncoderByFileExtensionString( ); } - public static function targetEncoderProvider(): array + public static function targetEncoderProvider(): Generator { - 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], - ]; + yield ['webp', WebpEncoder::class]; + yield ['avif', AvifEncoder::class]; + yield ['jpeg', JpegEncoder::class]; + yield ['jpg', JpegEncoder::class]; + yield ['bmp', BmpEncoder::class]; + yield ['gif', GifEncoder::class]; + yield ['png', PngEncoder::class]; + yield ['tiff', TiffEncoder::class]; + yield ['tif', TiffEncoder::class]; + yield ['jp2', Jpeg2000Encoder::class]; + yield ['heic', HeicEncoder::class]; + yield [FileExtension::WEBP, WebpEncoder::class]; + yield [FileExtension::AVIF, AvifEncoder::class]; + yield [FileExtension::JPG, JpegEncoder::class]; + yield [FileExtension::BMP, BmpEncoder::class]; + yield [FileExtension::GIF, GifEncoder::class]; + yield [FileExtension::PNG, PngEncoder::class]; + yield [FileExtension::TIF, TiffEncoder::class]; + yield [FileExtension::TIFF, TiffEncoder::class]; + yield [FileExtension::JP2, Jpeg2000Encoder::class]; + yield [FileExtension::HEIC, HeicEncoder::class]; } public function testArgumentsNotSupportedByTargetEncoder(): void diff --git a/tests/Unit/Encoders/MediaTypeEncoderTest.php b/tests/Unit/Encoders/MediaTypeEncoderTest.php index 713611ac..7d779bec 100644 --- a/tests/Unit/Encoders/MediaTypeEncoderTest.php +++ b/tests/Unit/Encoders/MediaTypeEncoderTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Encoders; +use Generator; use Intervention\Image\Encoders\AvifEncoder; use Intervention\Image\Encoders\BmpEncoder; use Intervention\Image\Encoders\GifEncoder; @@ -51,30 +52,28 @@ public function testEncoderByMediaType( ); } - public static function targetEncoderProvider(): array + public static function targetEncoderProvider(): Generator { - return [ - ['image/webp', WebpEncoder::class], - ['image/avif', AvifEncoder::class], - ['image/jpeg', JpegEncoder::class], - ['image/bmp', BmpEncoder::class], - ['image/gif', GifEncoder::class], - ['image/png', PngEncoder::class], - ['image/png', PngEncoder::class], - ['image/tiff', TiffEncoder::class], - ['image/jp2', Jpeg2000Encoder::class], - ['image/heic', HeicEncoder::class], - [MediaType::IMAGE_WEBP, WebpEncoder::class], - [MediaType::IMAGE_AVIF, AvifEncoder::class], - [MediaType::IMAGE_JPEG, JpegEncoder::class], - [MediaType::IMAGE_BMP, BmpEncoder::class], - [MediaType::IMAGE_GIF, GifEncoder::class], - [MediaType::IMAGE_PNG, PngEncoder::class], - [MediaType::IMAGE_TIFF, TiffEncoder::class], - [MediaType::IMAGE_JP2, Jpeg2000Encoder::class], - [MediaType::IMAGE_HEIC, HeicEncoder::class], - [MediaType::IMAGE_HEIF, HeicEncoder::class], - ]; + yield ['image/webp', WebpEncoder::class]; + yield ['image/avif', AvifEncoder::class]; + yield ['image/jpeg', JpegEncoder::class]; + yield ['image/bmp', BmpEncoder::class]; + yield ['image/gif', GifEncoder::class]; + yield ['image/png', PngEncoder::class]; + yield ['image/png', PngEncoder::class]; + yield ['image/tiff', TiffEncoder::class]; + yield ['image/jp2', Jpeg2000Encoder::class]; + yield ['image/heic', HeicEncoder::class]; + yield [MediaType::IMAGE_WEBP, WebpEncoder::class]; + yield [MediaType::IMAGE_AVIF, AvifEncoder::class]; + yield [MediaType::IMAGE_JPEG, JpegEncoder::class]; + yield [MediaType::IMAGE_BMP, BmpEncoder::class]; + yield [MediaType::IMAGE_GIF, GifEncoder::class]; + yield [MediaType::IMAGE_PNG, PngEncoder::class]; + yield [MediaType::IMAGE_TIFF, TiffEncoder::class]; + yield [MediaType::IMAGE_JP2, Jpeg2000Encoder::class]; + yield [MediaType::IMAGE_HEIC, HeicEncoder::class]; + yield [MediaType::IMAGE_HEIF, HeicEncoder::class]; } public function testArgumentsNotSupportedByTargetEncoder(): void diff --git a/tests/Unit/FileExtensionTest.php b/tests/Unit/FileExtensionTest.php index 4092aabb..c5ec92bd 100644 --- a/tests/Unit/FileExtensionTest.php +++ b/tests/Unit/FileExtensionTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit; +use Generator; use Intervention\Image\FileExtension; use Intervention\Image\Format; use Intervention\Image\MediaType; @@ -91,19 +92,17 @@ public function testMediatypes(FileExtension $extension, int $mediaTypeCount, Me $this->assertEquals($mediaType, $extension->mediaType()); } - public static function mediaTypesDataProvider(): array + public static function mediaTypesDataProvider(): Generator { - return [ - [FileExtension::JPEG, 4, MediaType::IMAGE_JPEG], - [FileExtension::WEBP, 2, MediaType::IMAGE_WEBP], - [FileExtension::GIF, 1, MediaType::IMAGE_GIF], - [FileExtension::PNG, 2, MediaType::IMAGE_PNG], - [FileExtension::AVIF, 2, MediaType::IMAGE_AVIF], - [FileExtension::BMP, 8, MediaType::IMAGE_BMP], - [FileExtension::TIFF, 1, MediaType::IMAGE_TIFF], - [FileExtension::TIF, 1, MediaType::IMAGE_TIFF], - [FileExtension::JP2, 3, MediaType::IMAGE_JP2], - [FileExtension::HEIC, 3, MediaType::IMAGE_HEIC], - ]; + yield [FileExtension::JPEG, 4, MediaType::IMAGE_JPEG]; + yield [FileExtension::WEBP, 2, MediaType::IMAGE_WEBP]; + yield [FileExtension::GIF, 1, MediaType::IMAGE_GIF]; + yield [FileExtension::PNG, 2, MediaType::IMAGE_PNG]; + yield [FileExtension::AVIF, 2, MediaType::IMAGE_AVIF]; + yield [FileExtension::BMP, 8, MediaType::IMAGE_BMP]; + yield [FileExtension::TIFF, 1, MediaType::IMAGE_TIFF]; + yield [FileExtension::TIF, 1, MediaType::IMAGE_TIFF]; + yield [FileExtension::JP2, 3, MediaType::IMAGE_JP2]; + yield [FileExtension::HEIC, 3, MediaType::IMAGE_HEIC]; } } diff --git a/tests/Unit/Geometry/RectangleResizerTest.php b/tests/Unit/Geometry/RectangleResizerTest.php index f5046d1b..ee54aa4d 100644 --- a/tests/Unit/Geometry/RectangleResizerTest.php +++ b/tests/Unit/Geometry/RectangleResizerTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit\Geometry; +use Generator; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use Intervention\Image\Geometry\Point; @@ -382,7 +383,7 @@ public function testScaleDown(): void } #[DataProvider('coverDataProvider')] - public function testCover($origin, $target, $result): void + public function testCover(Rectangle $origin, Rectangle $target, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); @@ -391,23 +392,21 @@ public function testCover($origin, $target, $result): void $this->assertEquals($result->height(), $resized->height()); } - public static function coverDataProvider(): array + public static function coverDataProvider(): Generator { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(133, 100)], - [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(200, 150)], - [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(267, 200)], - [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(2000, 1500)], - [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(2667, 2000)], - [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)], - [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(160, 120)], - [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(100, 133)], - [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(800, 800)], - ]; + yield [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(133, 100)]; + yield [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(200, 150)]; + yield [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(267, 200)]; + yield [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(2000, 1500)]; + yield [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(2667, 2000)]; + yield [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)]; + yield [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(160, 120)]; + yield [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(100, 133)]; + yield [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(800, 800)]; } #[DataProvider('containDataProvider')] - public function testContain($origin, $target, $result): void + public function testContain(Rectangle $origin, Rectangle $target, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); @@ -416,23 +415,21 @@ public function testContain($origin, $target, $result): void $this->assertEquals($result->height(), $resized->height()); } - public static function containDataProvider(): array + public static function containDataProvider(): Generator { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(100, 75)], - [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(133, 100)], - [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(100, 75)], - [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(13, 10)], - [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(10, 8)], - [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)], - [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(120, 90)], - [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(75, 100)], - [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(600, 600)], - ]; + yield [new Rectangle(800, 600), new Rectangle(100, 100), new Rectangle(100, 75)]; + yield [new Rectangle(800, 600), new Rectangle(200, 100), new Rectangle(133, 100)]; + yield [new Rectangle(800, 600), new Rectangle(100, 200), new Rectangle(100, 75)]; + yield [new Rectangle(800, 600), new Rectangle(2000, 10), new Rectangle(13, 10)]; + yield [new Rectangle(800, 600), new Rectangle(10, 2000), new Rectangle(10, 8)]; + yield [new Rectangle(800, 600), new Rectangle(800, 600), new Rectangle(800, 600)]; + yield [new Rectangle(400, 300), new Rectangle(120, 120), new Rectangle(120, 90)]; + yield [new Rectangle(600, 800), new Rectangle(100, 100), new Rectangle(75, 100)]; + yield [new Rectangle(100, 100), new Rectangle(800, 600), new Rectangle(600, 600)]; } #[DataProvider('cropDataProvider')] - public function testCrop($origin, $target, $position, $result): void + public function testCrop(Rectangle $origin, Rectangle $target, string $position, Rectangle $result): void { $resizer = new RectangleResizer(); $resizer->toSize($target); @@ -443,17 +440,55 @@ public function testCrop($origin, $target, $position, $result): void $this->assertEquals($result->pivot()->y(), $resized->pivot()->y()); } - public static function cropDataProvider(): array + public static function cropDataProvider(): Generator { - return [ - [new Rectangle(800, 600), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(350, 250))], - [new Rectangle(800, 600), new Rectangle(200, 100), 'center', new Rectangle(200, 100, new Point(300, 250))], - [new Rectangle(800, 600), new Rectangle(100, 200), 'center', new Rectangle(100, 200, new Point(350, 200))], - [new Rectangle(800, 600), new Rectangle(2000, 10), 'center', new Rectangle(2000, 10, new Point(-600, 295))], - [new Rectangle(800, 600), new Rectangle(10, 2000), 'center', new Rectangle(10, 2000, new Point(395, -700))], - [new Rectangle(800, 600), new Rectangle(800, 600), 'center', new Rectangle(800, 600, new Point(0, 0))], - [new Rectangle(400, 300), new Rectangle(120, 120), 'center', new Rectangle(120, 120, new Point(140, 90))], - [new Rectangle(600, 800), new Rectangle(100, 100), 'center', new Rectangle(100, 100, new Point(250, 350))], + yield [ + new Rectangle(800, 600), + new Rectangle(100, 100), + 'center', + new Rectangle(100, 100, new Point(350, 250)) + ]; + yield [ + new Rectangle(800, 600), + new Rectangle(200, 100), + 'center', + new Rectangle(200, 100, new Point(300, 250)) + ]; + yield [ + new Rectangle(800, 600), + new Rectangle(100, 200), + 'center', + new Rectangle(100, 200, new Point(350, 200)) + ]; + yield [ + new Rectangle(800, 600), + new Rectangle(2000, 10), + 'center', + new Rectangle(2000, 10, new Point(-600, 295)) + ]; + yield [ + new Rectangle(800, 600), + new Rectangle(10, 2000), + 'center', + new Rectangle(10, 2000, new Point(395, -700)) + ]; + yield [ + new Rectangle(800, 600), + new Rectangle(800, 600), + 'center', + new Rectangle(800, 600, new Point(0, 0)) + ]; + yield [ + new Rectangle(400, 300), + new Rectangle(120, 120), + 'center', + new Rectangle(120, 120, new Point(140, 90)) + ]; + yield [ + new Rectangle(600, 800), + new Rectangle(100, 100), + 'center', + new Rectangle(100, 100, new Point(250, 350)) ]; } } diff --git a/tests/Unit/InputHandlerTest.php b/tests/Unit/InputHandlerTest.php index f231d8f1..d8845218 100644 --- a/tests/Unit/InputHandlerTest.php +++ b/tests/Unit/InputHandlerTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit; +use Generator; use Intervention\Image\Colors\Rgb\Decoders\HexColorDecoder; use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; @@ -33,7 +34,7 @@ public function testHandleDefaultDecoders(string $driver, mixed $input, string $ } } - public static function testHandleProvider(): array + public static function testHandleProvider(): Generator { $base = [ [null, DecoderException::class], @@ -49,16 +50,13 @@ public static function testHandleProvider(): array [file_get_contents(self::getTestResourcePath()), ImageInterface::class], ]; - $data = []; $drivers = [GdDriver::class, ImagickDriver::class]; foreach ($drivers as $driver) { foreach ($base as $line) { array_unshift($line, $driver); // prepend driver - $data[] = $line; + yield $line; } } - - return $data; } public function testResolveWithoutDriver(): void diff --git a/tests/Unit/MediaTypeTest.php b/tests/Unit/MediaTypeTest.php index aeca4bc2..f792e896 100644 --- a/tests/Unit/MediaTypeTest.php +++ b/tests/Unit/MediaTypeTest.php @@ -4,6 +4,7 @@ namespace Intervention\Image\Tests\Unit; +use Generator; use Intervention\Image\FileExtension; use Intervention\Image\Format; use Intervention\Image\MediaType; @@ -118,35 +119,33 @@ public function testFileExtensions( $this->assertEquals($fileExtension, $mediaType->fileExtension()); } - public static function fileExtensionsDataProvider(): array + public static function fileExtensionsDataProvider(): Generator { - return [ - [MediaType::IMAGE_JPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_JPG, 2, FileExtension::JPG], - [MediaType::IMAGE_PJPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_X_JPEG, 2, FileExtension::JPG], - [MediaType::IMAGE_WEBP, 1, FileExtension::WEBP], - [MediaType::IMAGE_X_WEBP, 1, FileExtension::WEBP], - [MediaType::IMAGE_GIF, 1, FileExtension::GIF], - [MediaType::IMAGE_PNG, 1, FileExtension::PNG], - [MediaType::IMAGE_X_PNG, 1, FileExtension::PNG], - [MediaType::IMAGE_AVIF, 1, FileExtension::AVIF], - [MediaType::IMAGE_X_AVIF, 1, FileExtension::AVIF], - [MediaType::IMAGE_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_MS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_BITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_MS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_WINDOWS_BMP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_WIN_BITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_X_XBITMAP, 1, FileExtension::BMP], - [MediaType::IMAGE_TIFF, 2, FileExtension::TIF], - [MediaType::IMAGE_JP2, 8, FileExtension::JP2], - [MediaType::IMAGE_JPX, 8, FileExtension::JP2], - [MediaType::IMAGE_JPM, 8, FileExtension::JP2], - [MediaType::IMAGE_HEIC, 2, FileExtension::HEIC], - [MediaType::IMAGE_X_HEIC, 2, FileExtension::HEIC], - [MediaType::IMAGE_HEIF, 2, FileExtension::HEIC], - ]; + yield [MediaType::IMAGE_JPEG, 2, FileExtension::JPG]; + yield [MediaType::IMAGE_JPG, 2, FileExtension::JPG]; + yield [MediaType::IMAGE_PJPEG, 2, FileExtension::JPG]; + yield [MediaType::IMAGE_X_JPEG, 2, FileExtension::JPG]; + yield [MediaType::IMAGE_WEBP, 1, FileExtension::WEBP]; + yield [MediaType::IMAGE_X_WEBP, 1, FileExtension::WEBP]; + yield [MediaType::IMAGE_GIF, 1, FileExtension::GIF]; + yield [MediaType::IMAGE_PNG, 1, FileExtension::PNG]; + yield [MediaType::IMAGE_X_PNG, 1, FileExtension::PNG]; + yield [MediaType::IMAGE_AVIF, 1, FileExtension::AVIF]; + yield [MediaType::IMAGE_X_AVIF, 1, FileExtension::AVIF]; + yield [MediaType::IMAGE_BMP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_MS_BMP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_BITMAP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_BMP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_MS_BMP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_WINDOWS_BMP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_WIN_BITMAP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_X_XBITMAP, 1, FileExtension::BMP]; + yield [MediaType::IMAGE_TIFF, 2, FileExtension::TIF]; + yield [MediaType::IMAGE_JP2, 8, FileExtension::JP2]; + yield [MediaType::IMAGE_JPX, 8, FileExtension::JP2]; + yield [MediaType::IMAGE_JPM, 8, FileExtension::JP2]; + yield [MediaType::IMAGE_HEIC, 2, FileExtension::HEIC]; + yield [MediaType::IMAGE_X_HEIC, 2, FileExtension::HEIC]; + yield [MediaType::IMAGE_HEIF, 2, FileExtension::HEIC]; } }