File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88use Sabberworm \CSS \Position \Position ;
99use Sabberworm \CSS \Position \Positionable ;
1010use Sabberworm \CSS \Renderable ;
11+ use Sabberworm \CSS \ShortClassNameProvider ;
1112
1213class Comment implements Positionable, Renderable
1314{
1415 use Position;
16+ use ShortClassNameProvider;
1517
1618 /**
1719 * @var string
@@ -54,6 +56,11 @@ public function render(OutputFormat $outputFormat): string
5456 */
5557 public function getArrayRepresentation (): array
5658 {
57- throw new \BadMethodCallException ('`getArrayRepresentation` is not yet implemented for ` ' . self ::class . '` ' );
59+ return [
60+ 'class ' => $ this ->getShortClassName (),
61+ // "contents" is the term used in the W3C specs:
62+ // https://www.w3.org/TR/CSS22/syndata.html#comments
63+ 'contents ' => $ this ->commentText ,
64+ ];
5865 }
5966}
Original file line number Diff line number Diff line change @@ -81,12 +81,27 @@ public function getLineNumberReturnsLineNumberProvidedToConstructor(): void
8181 /**
8282 * @test
8383 */
84- public function getArrayRepresentationThrowsException (): void
84+ public function getArrayRepresentationIncludesClassName (): void
8585 {
86- $ this ->expectException (\BadMethodCallException::class);
87-
8886 $ subject = new Comment ();
8987
90- $ subject ->getArrayRepresentation ();
88+ $ result = $ subject ->getArrayRepresentation ();
89+
90+ self ::assertArrayHasKey ('class ' , $ result );
91+ self ::assertSame ('Comment ' , $ result ['class ' ]);
92+ }
93+
94+ /**
95+ * @test
96+ */
97+ public function getArrayRepresentationIncludesContents (): void
98+ {
99+ $ contents = 'War. War never changes. ' ;
100+ $ subject = new Comment ($ contents );
101+
102+ $ result = $ subject ->getArrayRepresentation ();
103+
104+ self ::assertArrayHasKey ('contents ' , $ result );
105+ self ::assertSame ($ contents , $ result ['contents ' ]);
91106 }
92107}
You can’t perform that action at this time.
0 commit comments