1
0
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:
Oliver Vogel
2024-01-27 18:40:28 +01:00
parent 05cf4fdaa5
commit 5a3e8fd7bd
2 changed files with 69 additions and 0 deletions

View 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');
}
}

View 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)'));
}
}