File tree Expand file tree Collapse file tree 4 files changed +80
-1
lines changed Expand file tree Collapse file tree 4 files changed +80
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Please also have a look at our
21
21
22
22
### Changed
23
23
24
+ - Make ` Selector ` a ` Renderable ` (#1017 )
24
25
- Mark ` Selector::isValid() ` as ` @internal ` (#1037 )
25
26
- Mark parsing-related methods of most CSS elements as ` @internal ` (#908 )
26
27
- Mark ` OutputFormat::nextLevel() ` as ` @internal ` (#901 )
Original file line number Diff line number Diff line change 4
4
5
5
namespace Sabberworm \CSS \Property ;
6
6
7
+ use Sabberworm \CSS \OutputFormat ;
8
+ use Sabberworm \CSS \Renderable ;
9
+
7
10
/**
8
11
* Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this
9
12
* class.
10
13
*/
11
- class Selector
14
+ class Selector implements Renderable
12
15
{
13
16
/**
14
17
* regexp for specificity calculations
@@ -139,4 +142,9 @@ public function getSpecificity()
139
142
}
140
143
return $ this ->specificity ;
141
144
}
145
+
146
+ public function render (OutputFormat $ outputFormat ): string
147
+ {
148
+ return $ this ->getSelector ();
149
+ }
142
150
}
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 renderWithVirginOutputFormatRendersSelectorPassedToConstructor (): 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 renderWithDefaultOutputFormatRendersSelectorPassedToConstructor (): 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 renderWithCompactOutputFormatRendersSelectorPassedToConstructor (): 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 renderWithPrettyOutputFormatRendersSelectorPassedToConstructor (): 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 6
6
7
7
use PHPUnit \Framework \TestCase ;
8
8
use Sabberworm \CSS \Property \Selector ;
9
+ use Sabberworm \CSS \Renderable ;
9
10
10
11
/**
11
12
* @covers \Sabberworm\CSS\Property\Selector
12
13
*/
13
14
final class SelectorTest extends TestCase
14
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
+
15
26
/**
16
27
* @test
17
28
*/
You can’t perform that action at this time.
0 commit comments