1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 01:29:51 +02:00

Refactor encoder tests

This commit is contained in:
Oliver Vogel
2024-03-26 15:17:02 +01:00
parent f035f7d516
commit c261654599
15 changed files with 33 additions and 286 deletions

View File

@@ -6,33 +6,17 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\AvifEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Encoders\AvifEncoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\AvifEncoder::class)]
final class AvifEncoderTest extends BaseTestCase
final class AvifEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new AvifEncoder(10);
$result = $encoder->encode($image);
$this->assertMediaType('image/avif', (string) $result);

View File

@@ -6,12 +6,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\BmpEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
@@ -19,20 +14,9 @@ use Intervention\Image\Tests\ImagickTestCase;
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\BmpEncoder::class)]
final class BmpEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new BmpEncoder();
$result = $encoder->encode($image);
$this->assertMediaType(['image/bmp', 'image/x-ms-bmp'], (string) $result);

View File

@@ -6,12 +6,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\GifEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
@@ -19,34 +14,9 @@ use Intervention\Image\Tests\ImagickTestCase;
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\GifEncoder::class)]
final class GifEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$frame = new Imagick();
$frame->newImage(30, 20, new ImagickPixel('red'), 'png');
$frame->setImageDelay(50);
$imagick->addImage($frame);
$frame = new Imagick();
$frame->newImage(30, 20, new ImagickPixel('green'), 'png');
$frame->setImageDelay(50);
$imagick->addImage($frame);
$frame = new Imagick();
$frame->newImage(30, 20, new ImagickPixel('blue'), 'png');
$frame->setImageDelay(50);
$imagick->addImage($frame);
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new GifEncoder();
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);

View File

@@ -6,12 +6,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\HeicEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
@@ -19,20 +14,9 @@ use Intervention\Image\Tests\ImagickTestCase;
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\HeicEncoder::class)]
final class HeicEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'jpg');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new HeicEncoder(75);
$result = $encoder->encode($image);
$this->assertMediaType('image/heic', (string) $result);

View File

@@ -6,33 +6,17 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\Jpeg2000Encoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Encoders\Jpeg2000Encoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\Jpeg2000Encoder::class)]
final class Jpeg2000EncoderTest extends BaseTestCase
final class Jpeg2000EncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new Jpeg2000Encoder(75);
$result = $encoder->encode($image);
$this->assertMediaType('image/jp2', (string) $result);

View File

@@ -6,33 +6,17 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\JpegEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Encoders\JpegEncoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\JpegEncoder::class)]
final class JpegEncoderTest extends BaseTestCase
final class JpegEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new JpegEncoder(75);
$result = $encoder->encode($image);
$this->assertMediaType('image/jpeg', (string) $result);

View File

@@ -6,12 +6,7 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\PngEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
@@ -19,20 +14,9 @@ use Intervention\Image\Tests\ImagickTestCase;
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\PngEncoder::class)]
final class PngEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'jpg');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new PngEncoder(75);
$result = $encoder->encode($image);
$this->assertMediaType('image/png', (string) $result);

View File

@@ -6,33 +6,17 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\TiffEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Encoders\TiffEncoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\TiffEncoder::class)]
final class TiffEncoderTest extends BaseTestCase
final class TiffEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new TiffEncoder();
$result = $encoder->encode($image);
$this->assertMediaType('image/tiff', (string) $result);

View File

@@ -6,33 +6,17 @@ namespace Intervention\Image\Tests\Unit\Drivers\Imagick\Encoders;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\Imagick\Core;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Encoders\WebpEncoder;
use Intervention\Image\Image;
use Intervention\Image\Tests\BaseTestCase;
use Intervention\Image\Tests\ImagickTestCase;
#[RequiresPhpExtension('imagick')]
#[CoversClass(\Intervention\Image\Encoders\WebpEncoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Imagick\Encoders\WebpEncoder::class)]
final class WebpEncoderTest extends BaseTestCase
final class WebpEncoderTest extends ImagickTestCase
{
protected function getTestImage(): Image
{
$imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
return new Image(
new Driver(),
new Core($imagick)
);
}
public function testEncode(): void
{
$image = $this->getTestImage();
$image = $this->createTestImage(3, 2);
$encoder = new WebpEncoder(75);
$result = $encoder->encode($image);
$this->assertMediaType('image/webp', (string) $result);