File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99use Sabberworm \CSS \Parsing \SourceException ;
1010use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
1111use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
12+ use Sabberworm \CSS \ShortClassNameProvider ;
1213
1314use function Safe \preg_match ;
1415
1920 */
2021class CSSString extends PrimitiveValue
2122{
23+ use ShortClassNameProvider;
24+
2225 /**
2326 * @var string
2427 */
@@ -94,4 +97,18 @@ public function render(OutputFormat $outputFormat): string
9497 $ string = \str_replace ("\n" , '\\A ' , $ string );
9598 return $ outputFormat ->getStringQuotingType () . $ string . $ outputFormat ->getStringQuotingType ();
9699 }
100+
101+ /**
102+ * @return array<string, bool|int|float|string|list<array<string, mixed>>>
103+ *
104+ * @internal
105+ */
106+ public function getArrayRepresentation (): array
107+ {
108+ return [
109+ 'class ' => $ this ->getShortClassName (),
110+ // We're using the term "contents" here to make the difference to the class more clear.
111+ 'contents ' => $ this ->string ,
112+ ];
113+ }
97114}
Original file line number Diff line number Diff line change @@ -84,12 +84,27 @@ public function getLineNumberReturnsLineNumberProvidedToConstructor(): void
8484 /**
8585 * @test
8686 */
87- public function getArrayRepresentationThrowsException (): void
87+ public function getArrayRepresentationIncludesClassName (): void
8888 {
89- $ this ->expectException (\BadMethodCallException::class);
90-
9189 $ subject = new CSSString ('' );
9290
93- $ subject ->getArrayRepresentation ();
91+ $ result = $ subject ->getArrayRepresentation ();
92+
93+ self ::assertArrayHasKey ('class ' , $ result );
94+ self ::assertSame ('CSSString ' , $ result ['class ' ]);
95+ }
96+
97+ /**
98+ * @test
99+ */
100+ public function getArrayRepresentationIncludesContents (): void
101+ {
102+ $ contents = 'What is love? ' ;
103+ $ subject = new CSSString ($ contents );
104+
105+ $ result = $ subject ->getArrayRepresentation ();
106+
107+ self ::assertArrayHasKey ('contents ' , $ result );
108+ self ::assertSame ($ contents , $ result ['contents ' ]);
94109 }
95110}
You can’t perform that action at this time.
0 commit comments