From b0c295e2bcb889df1b195d6a74b35c2ab64d0bb7 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 18 Jan 2026 15:53:27 +0100 Subject: [PATCH] [TASK] Implement `Charset::getArrayRepresentation()` Part of #1440. --- src/Property/Charset.php | 7 ++++++- tests/Unit/Property/CharsetTest.php | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Property/Charset.php b/src/Property/Charset.php index 50c84928..10776808 100644 --- a/src/Property/Charset.php +++ b/src/Property/Charset.php @@ -8,6 +8,7 @@ use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Position\Position; use Sabberworm\CSS\Position\Positionable; +use Sabberworm\CSS\ShortClassNameProvider; use Sabberworm\CSS\Value\CSSString; /** @@ -22,6 +23,7 @@ class Charset implements AtRule, Positionable { use CommentContainer; use Position; + use ShortClassNameProvider; /** * @var CSSString @@ -79,6 +81,9 @@ public function atRuleArgs(): CSSString */ public function getArrayRepresentation(): array { - throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + return [ + 'class' => $this->getShortClassName(), + 'charset' => $this->charset->getArrayRepresentation(), + ]; } } diff --git a/tests/Unit/Property/CharsetTest.php b/tests/Unit/Property/CharsetTest.php index 6f8fa60d..3fc385af 100644 --- a/tests/Unit/Property/CharsetTest.php +++ b/tests/Unit/Property/CharsetTest.php @@ -35,10 +35,25 @@ public function implementsCSSListItem(): void /** * @test */ - public function getArrayRepresentationThrowsException(): void + public function getArrayRepresentationIncludesClassName(): void { - $this->expectException(\BadMethodCallException::class); + $result = $this->subject->getArrayRepresentation(); - $this->subject->getArrayRepresentation(); + self::assertArrayHasKey('class', $result); + self::assertSame('Charset', $result['class']); + } + + /** + * @test + */ + public function getArrayRepresentationIncludesCharset(): void + { + $charset = 'iso-8859-15'; + $subject = new Charset(new CSSString($charset)); + + $result = $subject->getArrayRepresentation(); + + self::assertArrayHasKey('charset', $result); + self::assertSame(['class' => 'CSSString', 'contents' => $charset], $result['charset']); } }