Skip to content

Commit 5e61f78

Browse files
committed
[TASK] Implement Selector::getArrayRepresentation()
This does not include the string value, because it will be changed in #1496.
1 parent b67aac0 commit 5e61f78

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/Property/Selector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Sabberworm\CSS\Property\Selector\CompoundSelector;
1414
use Sabberworm\CSS\Property\Selector\SpecificityCalculator;
1515
use Sabberworm\CSS\Renderable;
16+
use Sabberworm\CSS\ShortClassNameProvider;
1617

1718
use function Safe\preg_match;
1819
use function Safe\preg_replace;
@@ -23,6 +24,8 @@
2324
*/
2425
class Selector implements Renderable
2526
{
27+
use ShortClassNameProvider;
28+
2629
/**
2730
* @internal since 8.5.2
2831
*/
@@ -192,6 +195,8 @@ public function render(OutputFormat $outputFormat): string
192195
*/
193196
public function getArrayRepresentation(): array
194197
{
195-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
198+
return [
199+
'class' => $this->getShortClassName(),
200+
];
196201
}
197202
}

tests/Unit/Property/KeyframeSelectorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ final class KeyframeSelectorTest extends TestCase
1616
/**
1717
* @test
1818
*/
19-
public function getArrayRepresentationThrowsException(): void
19+
public function getArrayRepresentationIncludesClassName(): void
2020
{
21-
$this->expectException(\BadMethodCallException::class);
21+
$subject = new KeyframeSelector('');
2222

23-
$subject = new KeyframeSelector('a');
23+
$result = $subject->getArrayRepresentation();
2424

25-
$subject->getArrayRepresentation();
25+
self::assertSame('KeyframeSelector', $result['class']);
2626
}
2727
}

tests/Unit/Property/SelectorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,12 @@ public function doesNotCleanupSpacesWithinAttributeSelector(): void
458458
/**
459459
* @test
460460
*/
461-
public function getArrayRepresentationThrowsException(): void
461+
public function getArrayRepresentationIncludesClassName(): void
462462
{
463-
$this->expectException(\BadMethodCallException::class);
463+
$subject = new Selector('');
464464

465-
$subject = new Selector('a');
465+
$result = $subject->getArrayRepresentation();
466466

467-
$subject->getArrayRepresentation();
467+
self::assertSame('Selector', $result['class']);
468468
}
469469
}

0 commit comments

Comments
 (0)