Skip to content

Commit 560fb8c

Browse files
committed
[TASK] Test LineName::getArrayRepresentation()
The tests are basically the same as those for the parent class `ValueList`. The main difference is that the default separator now is a space, not a comma. Part of #1440.
1 parent 8ad8565 commit 560fb8c

2 files changed

Lines changed: 54 additions & 13 deletions

File tree

src/Value/LineName.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,4 @@ public function render(OutputFormat $outputFormat): string
5656
{
5757
return '[' . parent::render(OutputFormat::createCompact()) . ']';
5858
}
59-
60-
/**
61-
* @return array<string, bool|int|float|string|array<mixed>|null>
62-
*
63-
* @internal
64-
*/
65-
public function getArrayRepresentation(): array
66-
{
67-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
68-
}
6959
}

tests/Unit/Value/LineNameTest.php

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\TestCase;
88
use Sabberworm\CSS\Value\LineName;
9+
use Sabberworm\CSS\Value\Size;
910

1011
/**
1112
* @covers \Sabberworm\CSS\Value\LineName
@@ -17,12 +18,62 @@ final class LineNameTest extends TestCase
1718
/**
1819
* @test
1920
*/
20-
public function getArrayRepresentationThrowsException(): void
21+
public function getArrayRepresentationIncludesClassName(): void
2122
{
22-
$this->expectException(\BadMethodCallException::class);
23+
$subject = new LineName();
24+
25+
$result = $subject->getArrayRepresentation();
26+
27+
self::assertSame('LineName', $result['class']);
28+
}
29+
30+
/**
31+
* @test
32+
*/
33+
public function getArrayRepresentationIncludesStringComponent(): void
34+
{
35+
$subject = new LineName(['Helvetica']);
36+
37+
$result = $subject->getArrayRepresentation();
38+
39+
self::assertSame('Helvetica', $result['components'][0]['value']);
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function getArrayRepresentationIncludesValueComponent(): void
46+
{
47+
$subject = new LineName([new Size(1)]);
2348

49+
$result = $subject->getArrayRepresentation();
50+
51+
self::assertSame('Size', $result['components'][0]['class']);
52+
}
53+
54+
/**
55+
* @test
56+
*/
57+
public function getArrayRepresentationIncludesMultipleMixedComponents(): void
58+
{
59+
$subject = new LineName([new Size(1), '+', new Size(2)]);
60+
61+
$result = $subject->getArrayRepresentation();
62+
63+
self::assertSame('Size', $result['components'][0]['class']);
64+
self::assertSame('+', $result['components'][1]['value']);
65+
self::assertSame('Size', $result['components'][2]['class']);
66+
}
67+
68+
/**
69+
* @test
70+
*/
71+
public function getArrayRepresentationIncludesSpaceSeparator(): void
72+
{
2473
$subject = new LineName();
2574

26-
$subject->getArrayRepresentation();
75+
$result = $subject->getArrayRepresentation();
76+
77+
self::assertSame(' ', $result['separator']);
2778
}
2879
}

0 commit comments

Comments
 (0)