Skip to content

Commit 4186272

Browse files
authored
[TASK] Implement Import::getArrayRepresentation() (#1554)
Part of #1440.
1 parent c4f46fe commit 4186272

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/Property/Import.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sabberworm\CSS\OutputFormat;
99
use Sabberworm\CSS\Position\Position;
1010
use Sabberworm\CSS\Position\Positionable;
11+
use Sabberworm\CSS\ShortClassNameProvider;
1112
use Sabberworm\CSS\Value\URL;
1213

1314
/**
@@ -17,6 +18,7 @@ class Import implements AtRule, Positionable
1718
{
1819
use CommentContainer;
1920
use Position;
21+
use ShortClassNameProvider;
2022

2123
/**
2224
* @var URL
@@ -90,6 +92,11 @@ public function getMediaQuery(): ?string
9092
*/
9193
public function getArrayRepresentation(): array
9294
{
93-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
95+
return [
96+
'class' => $this->getShortClassName(),
97+
// We're using the term "uri" here to match the wording used in the specs:
98+
// https://www.w3.org/TR/CSS22/cascade.html#at-import
99+
'uri' => $this->location->getArrayRepresentation(),
100+
];
94101
}
95102
}

tests/Unit/Property/ImportTest.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,36 @@ public function implementsCSSListItem(): void
3636
/**
3737
* @test
3838
*/
39-
public function getArrayRepresentationThrowsException(): void
39+
public function getArrayRepresentationIncludesClassName(): void
4040
{
41-
$this->expectException(\BadMethodCallException::class);
41+
$subject = new Import(new URL(new CSSString('https://example.org/')), null);
4242

43-
$this->subject->getArrayRepresentation();
43+
$result = $subject->getArrayRepresentation();
44+
45+
self::assertSame('Import', $result['class']);
46+
}
47+
48+
/**
49+
* @test
50+
*/
51+
public function getArrayRepresentationIncludesUri(): void
52+
{
53+
$uri = 'https://example.com';
54+
$url = new URL(new CSSString($uri));
55+
56+
$subject = new Import($url, null);
57+
58+
$result = $subject->getArrayRepresentation();
59+
60+
self::assertSame(
61+
[
62+
'class' => 'URL',
63+
'uri' => [
64+
'class' => 'CSSString',
65+
'contents' => $uri,
66+
],
67+
],
68+
$result['uri']
69+
);
4470
}
4571
}

0 commit comments

Comments
 (0)