1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-01 11:30:16 +02:00

Add tests

This commit is contained in:
Oliver Vogel
2024-01-27 18:30:03 +01:00
parent ec906681d6
commit 05cf4fdaa5
5 changed files with 56 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ namespace Intervention\Image\Tests\Colors\Cmyk\Decoders;
use Intervention\Image\Colors\Cmyk\Color;
use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Tests\TestCase;
/**
@@ -29,9 +30,15 @@ class StringColorDecoderTest extends TestCase
$this->assertInstanceOf(Color::class, $result);
$this->assertEquals([0, 100, 100, 0], $result->toArray());
$result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)');
$this->assertInstanceOf(Color::class, $result);
$this->assertEquals([0, 100, 100, 0], $result->toArray());
}
public function testDecodeInvalid(): void
{
$decoder = new StringColorDecoder();
$this->expectException(DecoderException::class);
$decoder->decode(null);
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Modifiers\QuantizeColorsModifier;
use Intervention\Image\Tests\TestCase;
@@ -26,6 +27,21 @@ class QuantizeColorsModifierTest extends TestCase
$this->assertColorCount(4, $image);
}
public function testNoColorReduction(): void
{
$image = $this->readTestImage('gradient.bmp');
$this->assertColorCount(15, $image);
$image->modify(new QuantizeColorsModifier(150));
$this->assertColorCount(15, $image);
}
public function testInvalidColorInput(): void
{
$image = $this->readTestImage('gradient.bmp');
$this->expectException(InputException::class);
$image->modify(new QuantizeColorsModifier(0));
}
private function assertColorCount(int $count, ImageInterface $image): void
{
$colors = [];

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Modifiers\RemoveAnimationModifier;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
@@ -34,4 +35,11 @@ class RemoveAnimationModifierTest extends TestCase
$this->assertEquals(1, count($image));
$this->assertEquals(1, count($result));
}
public function testApplyInvalid(): void
{
$image = $this->readTestImage('animation.gif');
$this->expectException(InputException::class);
$image->modify(new RemoveAnimationModifier('test'));
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Modifiers\QuantizeColorsModifier;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
@@ -24,4 +25,19 @@ class QuantizeColorsModifierTest extends TestCase
$image->modify(new QuantizeColorsModifier(4));
$this->assertEquals(4, $image->core()->native()->getImageColors());
}
public function testNoColorReduction(): void
{
$image = $this->readTestImage('gradient.bmp');
$this->assertEquals(15, $image->core()->native()->getImageColors());
$image->modify(new QuantizeColorsModifier(150));
$this->assertEquals(15, $image->core()->native()->getImageColors());
}
public function testInvalidColorInput(): void
{
$image = $this->readTestImage('gradient.bmp');
$this->expectException(InputException::class);
$image->modify(new QuantizeColorsModifier(0));
}
}

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Modifiers\RemoveAnimationModifier;
use Intervention\Image\Tests\TestCase;
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
@@ -34,4 +35,11 @@ class RemoveAnimationModifierTest extends TestCase
$this->assertEquals(1, count($image));
$this->assertEquals(1, count($result));
}
public function testApplyInvalid(): void
{
$image = $this->readTestImage('animation.gif');
$this->expectException(InputException::class);
$image->modify(new RemoveAnimationModifier('test'));
}
}