mirror of
https://github.com/Intervention/image.git
synced 2025-09-01 09:52:59 +02:00
Add color processor tests
This commit is contained in:
42
tests/Drivers/Gd/ColorProcessorTest.php
Normal file
42
tests/Drivers/Gd/ColorProcessorTest.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Intervention\Image\Tests\Drivers\Gd;
|
||||||
|
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Alpha;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Blue;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Green;
|
||||||
|
use Intervention\Image\Colors\Rgb\Channels\Red;
|
||||||
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
|
use Intervention\Image\Drivers\Gd\ColorProcessor;
|
||||||
|
use Intervention\Image\Exceptions\ColorException;
|
||||||
|
use Intervention\Image\Tests\TestCase;
|
||||||
|
|
||||||
|
class ColorProcessorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testColorToNative(): void
|
||||||
|
{
|
||||||
|
$processor = new ColorProcessor();
|
||||||
|
$result = $processor->colorToNative(new Color(255, 55, 0, 255));
|
||||||
|
$this->assertEquals(16725760, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNativeToColor(): void
|
||||||
|
{
|
||||||
|
$processor = new ColorProcessor();
|
||||||
|
$result = $processor->nativeToColor(16725760);
|
||||||
|
$this->assertInstanceOf(Color::class, $result);
|
||||||
|
$this->assertEquals(255, $result->channel(Red::class)->value());
|
||||||
|
$this->assertEquals(55, $result->channel(Green::class)->value());
|
||||||
|
$this->assertEquals(0, $result->channel(Blue::class)->value());
|
||||||
|
$this->assertEquals(255, $result->channel(Alpha::class)->value());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNativeToColorInvalid(): void
|
||||||
|
{
|
||||||
|
$processor = new ColorProcessor();
|
||||||
|
$this->expectException(ColorException::class);
|
||||||
|
$processor->nativeToColor('test');
|
||||||
|
}
|
||||||
|
}
|
27
tests/Drivers/Imagick/ColorProcessorTest.php
Normal file
27
tests/Drivers/Imagick/ColorProcessorTest.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Intervention\Image\Tests\Drivers\Imagick;
|
||||||
|
|
||||||
|
use ImagickPixel;
|
||||||
|
use Intervention\Image\Colors\Rgb\Color;
|
||||||
|
use Intervention\Image\Colors\Rgb\Colorspace;
|
||||||
|
use Intervention\Image\Drivers\Imagick\ColorProcessor;
|
||||||
|
use Intervention\Image\Tests\TestCase;
|
||||||
|
|
||||||
|
class ColorProcessorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testColorToNative(): void
|
||||||
|
{
|
||||||
|
$processor = new ColorProcessor(new Colorspace());
|
||||||
|
$result = $processor->colorToNative(new Color(255, 55, 0, 255));
|
||||||
|
$this->assertInstanceOf(ImagickPixel::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNativeToColor(): void
|
||||||
|
{
|
||||||
|
$processor = new ColorProcessor(new Colorspace());
|
||||||
|
$result = $processor->nativeToColor(new ImagickPixel('rgb(255, 55, 0)'));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user