From ddbb13972b6482448639db94e6830d60fa5145dd Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 5 Jan 2026 10:40:13 +0100 Subject: [PATCH 1/2] [TASK] Implement `URL::getArrayRepresentation()` Part of #1440. --- src/Value/URL.php | 18 ++++++++++++++++++ tests/Unit/Value/URLTest.php | 23 +++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Value/URL.php b/src/Value/URL.php index f6e7b974a..1ecfe3238 100644 --- a/src/Value/URL.php +++ b/src/Value/URL.php @@ -9,12 +9,15 @@ use Sabberworm\CSS\Parsing\SourceException; use Sabberworm\CSS\Parsing\UnexpectedEOFException; use Sabberworm\CSS\Parsing\UnexpectedTokenException; +use Sabberworm\CSS\ShortClassNameProvider; /** * This class represents URLs in CSS. `URL`s always output in `URL("")` notation. */ class URL extends PrimitiveValue { + use ShortClassNameProvider; + /** * @var CSSString */ @@ -80,4 +83,19 @@ public function render(OutputFormat $outputFormat): string { return "url({$this->url->render($outputFormat)})"; } + + /** + * @return array|null> + * + * @internal + */ + public function getArrayRepresentation(): array + { + return [ + 'class' => $this->getShortClassName(), + // We're using the term "uri" here to terminology the wording used in the specs: + // https://www.w3.org/TR/CSS22/syndata.html#uri + 'uri' => $this->url->getArrayRepresentation(), + ]; + } } diff --git a/tests/Unit/Value/URLTest.php b/tests/Unit/Value/URLTest.php index 8b4c08809..9cdda5dc2 100644 --- a/tests/Unit/Value/URLTest.php +++ b/tests/Unit/Value/URLTest.php @@ -84,12 +84,27 @@ public function getLineNumberReturnsLineNumberProvidedToConstructor(): void /** * @test */ - public function getArrayRepresentationThrowsException(): void + public function getArrayRepresentationIncludesClassName(): void { - $this->expectException(\BadMethodCallException::class); + $subject = new URL(new CSSString('https://example.com')); - $subject = new URL(new CSSString('http://example.com')); + $result = $subject->getArrayRepresentation(); + + self::assertArrayHasKey('class', $result); + self::assertSame('URL', $result['class']); + } + + /** + * @test + */ + public function getArrayRepresentationIncludesUri(): void + { + $uri = 'https://example.com'; + $subject = new URL(new CSSString($uri)); + + $result = $subject->getArrayRepresentation(); - $subject->getArrayRepresentation(); + self::assertArrayHasKey('uri', $result); + self::assertSame(['class' => 'CSSString', 'contents' => $uri], $result['uri']); } } From a2ef9eb842d3712c307376c2136a8bd81677197f Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 5 Jan 2026 23:31:16 +0100 Subject: [PATCH 2/2] Update src/Value/URL.php Co-authored-by: JakeQZ --- src/Value/URL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Value/URL.php b/src/Value/URL.php index 1ecfe3238..55ee04f17 100644 --- a/src/Value/URL.php +++ b/src/Value/URL.php @@ -93,7 +93,7 @@ public function getArrayRepresentation(): array { return [ 'class' => $this->getShortClassName(), - // We're using the term "uri" here to terminology the wording used in the specs: + // We're using the term "uri" here to match the wording used in the specs: // https://www.w3.org/TR/CSS22/syndata.html#uri 'uri' => $this->url->getArrayRepresentation(), ];