1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-23 05:52:47 +02:00
Files
intervention_image/tests/Unit/Drivers/Gd/Encoders/PngEncoderTest.php
Oliver Vogel b9a16d4df6 Optimize tests
2024-12-07 11:38:33 +01:00

95 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders;
use Generator;
use Intervention\Image\Drivers\Gd\Encoders\PngEncoder;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Tests\GdTestCase;
use Intervention\Image\Tests\Traits\CanInspectPngFormat;
use PHPUnit\Framework\Attributes\DataProvider;
#[RequiresPhpExtension('gd')]
#[CoversClass(PngEncoder::class)]
final class PngEncoderTest extends GdTestCase
{
use CanInspectPngFormat;
public function testEncode(): void
{
$image = $this->createTestImage(3, 2);
$encoder = new PngEncoder();
$result = $encoder->encode($image);
$this->assertMediaType('image/png', $result);
$this->assertEquals('image/png', $result->mimetype());
$this->assertFalse($this->isInterlacedPng($result));
}
public function testEncodeInterlaced(): void
{
$image = $this->createTestImage(3, 2);
$encoder = new PngEncoder(interlaced: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/png', $result);
$this->assertEquals('image/png', $result->mimetype());
$this->assertTrue($this->isInterlacedPng($result));
}
#[DataProvider('indexedDataProvider')]
public function testEncoderIndexed(ImageInterface $image, PngEncoder $encoder, string $result): void
{
$this->assertEquals(
$result,
$this->pngColorType($encoder->encode($image)),
);
}
public static function indexedDataProvider(): Generator
{
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',
];
}
}