File tree Expand file tree Collapse file tree 5 files changed +129
-1
lines changed
FunctionalDeprecated/Property Expand file tree Collapse file tree 5 files changed +129
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Please also have a look at our
1010
1111### Added
1212
13+ - Make ` Selector ` a ` Renderable ` (#1017 )
1314- ` OutputFormat ` properties for space around specific list separators (#880 )
1415- Partial support for CSS Color Module Level 4:
1516 - ` rgb ` and ` rgba ` , and ` hsl ` and ` hsla ` are now aliases (#797 }
Original file line number Diff line number Diff line change 44
55namespace Sabberworm \CSS \Property ;
66
7+ use Sabberworm \CSS \OutputFormat ;
8+ use Sabberworm \CSS \Renderable ;
9+
710/**
811 * Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this
912 * class.
1013 */
11- class Selector
14+ class Selector implements Renderable
1215{
1316 /**
1417 * regexp for specificity calculations
@@ -137,4 +140,19 @@ public function getSpecificity()
137140 }
138141 return $ this ->specificity ;
139142 }
143+
144+ public function render (OutputFormat $ outputFormat ): string
145+ {
146+ return $ this ->getSelector ();
147+ }
148+
149+ /**
150+ * @return never
151+ *
152+ * @throws \BadMethodCallException
153+ */
154+ public function getLineNo (): int
155+ {
156+ throw new \BadMethodCallException ('Not implemented ' , 1740654131 );
157+ }
140158}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Sabberworm \CSS \Tests \Functional \Selector ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use Sabberworm \CSS \OutputFormat ;
9+ use Sabberworm \CSS \Property \Selector ;
10+
11+ /**
12+ * @covers \Sabberworm\CSS\Property\Selector
13+ */
14+ final class SelectorTest extends TestCase
15+ {
16+ /**
17+ * @test
18+ */
19+ public function renderWithVirginOutputFormatRendersPatternPassedToConstructor (): void
20+ {
21+ $ pattern = 'a ' ;
22+ $ subject = new Selector ($ pattern );
23+
24+ self ::assertSame ($ pattern , $ subject ->render (new OutputFormat ()));
25+ }
26+
27+ /**
28+ * @test
29+ */
30+ public function renderWithDefaultOutputFormatRendersPatternPassedToConstructor (): void
31+ {
32+ $ pattern = 'a ' ;
33+ $ subject = new Selector ($ pattern );
34+
35+ self ::assertSame ($ pattern , $ subject ->render (OutputFormat::create ()));
36+ }
37+
38+ /**
39+ * @test
40+ */
41+ public function renderWithCompactOutputFormatRendersPatternPassedToConstructor (): void
42+ {
43+ $ pattern = 'a ' ;
44+ $ subject = new Selector ($ pattern );
45+
46+ self ::assertSame ($ pattern , $ subject ->render (OutputFormat::createCompact ()));
47+ }
48+
49+ /**
50+ * @test
51+ */
52+ public function renderWithPrettyOutputFormatRendersPatternPassedToConstructor (): void
53+ {
54+ $ pattern = 'a ' ;
55+ $ subject = new Selector ($ pattern );
56+
57+ self ::assertSame ($ pattern , $ subject ->render (OutputFormat::createPretty ()));
58+ }
59+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Sabberworm \CSS \Tests \FunctionalDeperecated \Selector ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use Sabberworm \CSS \Property \Selector ;
9+
10+ /**
11+ * @covers \Sabberworm\CSS\Property\Selector
12+ */
13+ final class SelectorTest extends TestCase
14+ {
15+ /**
16+ * @test
17+ */
18+ public function toStringReturnsPatternPassedToConstructor (): void
19+ {
20+ $ pattern = 'a ' ;
21+ $ subject = new Selector ($ pattern );
22+
23+ self ::assertSame ($ pattern , (string ) $ subject );
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Sabberworm \CSS \Tests \Unit \Property ;
6+
7+ use PHPUnit \Framework \TestCase ;
8+ use Sabberworm \CSS \Property \Selector ;
9+ use Sabberworm \CSS \Renderable ;
10+
11+ /**
12+ * @covers \Sabberworm\CSS\Property\Selector
13+ */
14+ final class SelectorTest extends TestCase
15+ {
16+ /**
17+ * @test
18+ */
19+ public function implementsRenderable (): void
20+ {
21+ $ subject = new Selector ('a ' );
22+
23+ self ::assertInstanceOf (Renderable::class, $ subject );
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments