diff --git a/src/Value/Color.php b/src/Value/Color.php index e79718f0..a043aad6 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -239,16 +239,6 @@ public function render(OutputFormat $outputFormat): string return parent::render($outputFormat); } - /** - * @return array|null> - * - * @internal - */ - public function getArrayRepresentation(): array - { - throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); - } - private function shouldRenderAsHex(OutputFormat $outputFormat): bool { return diff --git a/tests/Unit/Value/ColorTest.php b/tests/Unit/Value/ColorTest.php index 0311f9e5..862688a8 100644 --- a/tests/Unit/Value/ColorTest.php +++ b/tests/Unit/Value/ColorTest.php @@ -475,12 +475,41 @@ public function throwsExceptionWithInvalidColor(string $color): void /** * @test */ - public function getArrayRepresentationThrowsException(): void + public function getArrayRepresentationIncludesClassName(): void { - $this->expectException(\BadMethodCallException::class); + $subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']); - $subject = new Color([]); + $result = $subject->getArrayRepresentation(); - $subject->getArrayRepresentation(); + self::assertSame('Color', $result['class']); + } + + /** + * @test + */ + public function getArrayRepresentationIncludesValueKeysAsName(): void + { + $subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']); + + $result = $subject->getArrayRepresentation(); + + self::assertSame('rgb', $result['name']); + } + + /** + * @test + */ + public function getArrayRepresentationIncludesValueAsComponents(): void + { + $subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']); + + $result = $subject->getArrayRepresentation(); + + $expected = [ + 'r' => ['class' => 'string', 'value' => '10'], + 'g' => ['class' => 'string', 'value' => '20'], + 'b' => ['class' => 'string', 'value' => '30'], + ]; + self::assertSame($expected, $result['components']); } }