From 5a3e8fd7bdc2b7caea46f62e63798494331ee055 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 27 Jan 2024 18:40:28 +0100 Subject: [PATCH] Add color processor tests --- tests/Drivers/Gd/ColorProcessorTest.php | 42 ++++++++++++++++++++ tests/Drivers/Imagick/ColorProcessorTest.php | 27 +++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/Drivers/Gd/ColorProcessorTest.php create mode 100644 tests/Drivers/Imagick/ColorProcessorTest.php diff --git a/tests/Drivers/Gd/ColorProcessorTest.php b/tests/Drivers/Gd/ColorProcessorTest.php new file mode 100644 index 00000000..c33b71e2 --- /dev/null +++ b/tests/Drivers/Gd/ColorProcessorTest.php @@ -0,0 +1,42 @@ +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'); + } +} diff --git a/tests/Drivers/Imagick/ColorProcessorTest.php b/tests/Drivers/Imagick/ColorProcessorTest.php new file mode 100644 index 00000000..5515b581 --- /dev/null +++ b/tests/Drivers/Imagick/ColorProcessorTest.php @@ -0,0 +1,27 @@ +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)')); + } +}