Skip to content

Commit

Permalink
Refactor Jpeg200EncoderTest::class
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 29, 2024
1 parent c4ff66b commit bbc9874
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 0 additions & 10 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ protected function assertMediaType(string|array $allowed, string|EncodedImage $i
);
}

protected function assertMediaTypeJpeg2000(string|EncodedImage $input): void
{
$sample = strtoupper(substr(bin2hex((string) $input), 0, 24));

$this->assertTrue(
preg_match("/^0000000C6A5020200D0A870A|FF4FFF51/", $sample) === 1,
'Detected MIME type does not belong to the Jpeg 2000 format.'
);
}

protected function assertTransparency(ColorInterface $color): void
{
$this->assertInstanceOf(RgbColor::class, $color);
Expand Down
11 changes: 10 additions & 1 deletion tests/Unit/Encoders/Jpeg200EncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Intervention\Image\Drivers\Vips\Driver;
use Intervention\Image\Drivers\Vips\Encoders\Jpeg2000Encoder;
use Intervention\Image\Drivers\Vips\Tests\BaseTestCase;
use Intervention\Image\EncodedImage;
use PHPUnit\Framework\Attributes\CoversClass;

#[CoversClass(Jpeg2000Encoder::class)]
Expand All @@ -18,7 +19,15 @@ public function testEncode(): void
$encoder = new Jpeg2000Encoder(75);
$encoder->setDriver(new Driver());
$result = $encoder->encode($image);
$this->assertMediaTypeJpeg2000($result);
$this->assertEquals('image/jp2', $result->mimetype());
$this->assertTrue($this->isJpeg2000($result), 'Encoding result is not in Jpeg 2000 format.');
}

private function isJpeg2000(string|EncodedImage $input): bool
{
return 1 === preg_match(
"/^0000000C6A5020200D0A870A|FF4FFF51/",
strtoupper(substr(bin2hex((string) $input), 0, 24))
);
}
}

0 comments on commit bbc9874

Please sign in to comment.