From 5068d04b2fb30e6a5e63ffde4170210662f6768c Mon Sep 17 00:00:00 2001 From: Tim Van Dijck Date: Fri, 8 Dec 2023 15:26:31 +0100 Subject: [PATCH] Fix Heic and Tiff test. --- tests/ImageFormatTest.php | 17 ++++++++++++++--- tests/Pest.php | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/ImageFormatTest.php b/tests/ImageFormatTest.php index fe780306..fde16bb8 100644 --- a/tests/ImageFormatTest.php +++ b/tests/ImageFormatTest.php @@ -5,7 +5,6 @@ use Spatie\Image\Image; it('can save supported formats', function (ImageDriver $driver, string $format) { - $targetFile = $this->tempDir->path("{$driver->driverName()}/format-test.$format"); $driver->load(getTestJpg())->save($targetFile); @@ -13,7 +12,19 @@ expect($targetFile)->toHaveMime("image/$format"); })->with('drivers', ['jpeg', 'gif', 'png', 'webp']); -it('can save Imagick specific formats', function (string $format) { +it('can save tiff', function () { + $format = 'tiff'; + $driver = Image::useImageDriver('imagick'); + + $targetFile = $this->tempDir->path("{$driver->driverName()}/format-test.$format"); + + $driver->load(getTestJpg())->save($targetFile); + + expect($targetFile)->toHaveMime("image/$format"); +})->skipIfImagickDoesNotSupportFormat('tiff'); + +it('can save heic', function () { + $format = 'heic'; $driver = Image::useImageDriver('imagick'); $targetFile = $this->tempDir->path("{$driver->driverName()}/format-test.$format"); @@ -21,7 +32,7 @@ $driver->load(getTestJpg())->save($targetFile); expect($targetFile)->toHaveMime("image/$format"); -})->with(['heic', 'tiff']); +})->skipIfImagickDoesNotSupportFormat('heic'); it('throws an error for unsupported GD image formats', function (string $format) { $driver = Image::useImageDriver('gd'); diff --git a/tests/Pest.php b/tests/Pest.php index 3b3fa6fa..c78f5a48 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -63,3 +63,10 @@ function assertImageType(string $filePath, $expectedType): void expect($actualMime)->toBe($expectedMime); }); + +function skipIfImagickDoesNotSupportFormat(string $format) +{ + if (! in_array(strtoupper($format), Imagick::queryFormats('*'))) { + test()->markTestSkipped('Imagick does not support this format.'); + } +}