Skip to content

Commit 8b3dd42

Browse files
authored
[TASK] Add tests for Color::getArrayRepresentation() (#1606)
Part of #1440.
1 parent 8f6962c commit 8b3dd42

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/Value/Color.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,6 @@ public function render(OutputFormat $outputFormat): string
239239
return parent::render($outputFormat);
240240
}
241241

242-
/**
243-
* @return array<string, bool|int|float|string|array<mixed>|null>
244-
*
245-
* @internal
246-
*/
247-
public function getArrayRepresentation(): array
248-
{
249-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
250-
}
251-
252242
private function shouldRenderAsHex(OutputFormat $outputFormat): bool
253243
{
254244
return

tests/Unit/Value/ColorTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,41 @@ public function throwsExceptionWithInvalidColor(string $color): void
475475
/**
476476
* @test
477477
*/
478-
public function getArrayRepresentationThrowsException(): void
478+
public function getArrayRepresentationIncludesClassName(): void
479479
{
480-
$this->expectException(\BadMethodCallException::class);
480+
$subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']);
481481

482-
$subject = new Color([]);
482+
$result = $subject->getArrayRepresentation();
483483

484-
$subject->getArrayRepresentation();
484+
self::assertSame('Color', $result['class']);
485+
}
486+
487+
/**
488+
* @test
489+
*/
490+
public function getArrayRepresentationIncludesValueKeysAsName(): void
491+
{
492+
$subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']);
493+
494+
$result = $subject->getArrayRepresentation();
495+
496+
self::assertSame('rgb', $result['name']);
497+
}
498+
499+
/**
500+
* @test
501+
*/
502+
public function getArrayRepresentationIncludesValueAsComponents(): void
503+
{
504+
$subject = new Color(['r' => '10', 'g' => '20', 'b' => '30']);
505+
506+
$result = $subject->getArrayRepresentation();
507+
508+
$expected = [
509+
'r' => ['class' => 'string', 'value' => '10'],
510+
'g' => ['class' => 'string', 'value' => '20'],
511+
'b' => ['class' => 'string', 'value' => '30'],
512+
];
513+
self::assertSame($expected, $result['components']);
485514
}
486515
}

0 commit comments

Comments
 (0)