Skip to content

Commit

Permalink
Fix Heic and Tiff test.
Browse files Browse the repository at this point in the history
  • Loading branch information
timvandijck committed Dec 8, 2023
1 parent a4fc473 commit 5068d04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tests/ImageFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@
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);

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");

$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');
Expand Down
7 changes: 7 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

0 comments on commit 5068d04

Please sign in to comment.