Skip to content

Commit b0c295e

Browse files
committed
[TASK] Implement Charset::getArrayRepresentation()
Part of #1440.
1 parent b36a6ac commit b0c295e

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/Property/Charset.php

Lines changed: 6 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\CSSString;
1213

1314
/**
@@ -22,6 +23,7 @@ class Charset implements AtRule, Positionable
2223
{
2324
use CommentContainer;
2425
use Position;
26+
use ShortClassNameProvider;
2527

2628
/**
2729
* @var CSSString
@@ -79,6 +81,9 @@ public function atRuleArgs(): CSSString
7981
*/
8082
public function getArrayRepresentation(): array
8183
{
82-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
84+
return [
85+
'class' => $this->getShortClassName(),
86+
'charset' => $this->charset->getArrayRepresentation(),
87+
];
8388
}
8489
}

tests/Unit/Property/CharsetTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,25 @@ public function implementsCSSListItem(): void
3535
/**
3636
* @test
3737
*/
38-
public function getArrayRepresentationThrowsException(): void
38+
public function getArrayRepresentationIncludesClassName(): void
3939
{
40-
$this->expectException(\BadMethodCallException::class);
40+
$result = $this->subject->getArrayRepresentation();
4141

42-
$this->subject->getArrayRepresentation();
42+
self::assertArrayHasKey('class', $result);
43+
self::assertSame('Charset', $result['class']);
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function getArrayRepresentationIncludesCharset(): void
50+
{
51+
$charset = 'iso-8859-15';
52+
$subject = new Charset(new CSSString($charset));
53+
54+
$result = $subject->getArrayRepresentation();
55+
56+
self::assertArrayHasKey('charset', $result);
57+
self::assertSame(['class' => 'CSSString', 'contents' => $charset], $result['charset']);
4358
}
4459
}

0 commit comments

Comments
 (0)