Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -22,6 +23,7 @@ class Charset implements AtRule, Positionable
{
use CommentContainer;
use Position;
use ShortClassNameProvider;

/**
* @var CSSString
Expand Down Expand Up @@ -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(),
];
}
}
21 changes: 18 additions & 3 deletions tests/Unit/Property/CharsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}