mirror of
https://github.com/Intervention/image.git
synced 2025-08-06 13:56:30 +02:00
Add tests
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Intervention\Image\Tests\Colors\Cmyk\Decoders;
|
|||||||
|
|
||||||
use Intervention\Image\Colors\Cmyk\Color;
|
use Intervention\Image\Colors\Cmyk\Color;
|
||||||
use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder;
|
use Intervention\Image\Colors\Cmyk\Decoders\StringColorDecoder;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,9 +30,15 @@ class StringColorDecoderTest extends TestCase
|
|||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
$this->assertEquals([0, 100, 100, 0], $result->toArray());
|
$this->assertEquals([0, 100, 100, 0], $result->toArray());
|
||||||
|
|
||||||
|
|
||||||
$result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)');
|
$result = $decoder->decode('cmyk(0%, 100%, 100%, 0%)');
|
||||||
$this->assertInstanceOf(Color::class, $result);
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
$this->assertEquals([0, 100, 100, 0], $result->toArray());
|
$this->assertEquals([0, 100, 100, 0], $result->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDecodeInvalid(): void
|
||||||
|
{
|
||||||
|
$decoder = new StringColorDecoder();
|
||||||
|
$this->expectException(DecoderException::class);
|
||||||
|
$decoder->decode(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Modifiers\QuantizeColorsModifier;
|
use Intervention\Image\Modifiers\QuantizeColorsModifier;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
@@ -26,6 +27,21 @@ class QuantizeColorsModifierTest extends TestCase
|
|||||||
$this->assertColorCount(4, $image);
|
$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
|
private function assertColorCount(int $count, ImageInterface $image): void
|
||||||
{
|
{
|
||||||
$colors = [];
|
$colors = [];
|
||||||
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||||
@@ -34,4 +35,11 @@ class RemoveAnimationModifierTest extends TestCase
|
|||||||
$this->assertEquals(1, count($image));
|
$this->assertEquals(1, count($image));
|
||||||
$this->assertEquals(1, count($result));
|
$this->assertEquals(1, count($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testApplyInvalid(): void
|
||||||
|
{
|
||||||
|
$image = $this->readTestImage('animation.gif');
|
||||||
|
$this->expectException(InputException::class);
|
||||||
|
$image->modify(new RemoveAnimationModifier('test'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Modifiers\QuantizeColorsModifier;
|
use Intervention\Image\Modifiers\QuantizeColorsModifier;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||||
@@ -24,4 +25,19 @@ class QuantizeColorsModifierTest extends TestCase
|
|||||||
$image->modify(new QuantizeColorsModifier(4));
|
$image->modify(new QuantizeColorsModifier(4));
|
||||||
$this->assertEquals(4, $image->core()->native()->getImageColors());
|
$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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Exceptions\InputException;
|
||||||
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
use Intervention\Image\Modifiers\RemoveAnimationModifier;
|
||||||
use Intervention\Image\Tests\TestCase;
|
use Intervention\Image\Tests\TestCase;
|
||||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||||
@@ -34,4 +35,11 @@ class RemoveAnimationModifierTest extends TestCase
|
|||||||
$this->assertEquals(1, count($image));
|
$this->assertEquals(1, count($image));
|
||||||
$this->assertEquals(1, count($result));
|
$this->assertEquals(1, count($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testApplyInvalid(): void
|
||||||
|
{
|
||||||
|
$image = $this->readTestImage('animation.gif');
|
||||||
|
$this->expectException(InputException::class);
|
||||||
|
$image->modify(new RemoveAnimationModifier('test'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user