7
7
use PHPUnit \Framework \TestCase ;
8
8
use Sabberworm \CSS \CSSElement ;
9
9
use Sabberworm \CSS \CSSList \CSSListItem ;
10
- use Sabberworm \CSS \Tests \Unit \RuleSet \Fixtures \ConcreteRuleSet ;
10
+ use Sabberworm \CSS \OutputFormat ;
11
+ use Sabberworm \CSS \Rule \Rule ;
12
+ use Sabberworm \CSS \RuleSet \RuleSet ;
11
13
12
14
/**
13
15
* @covers \Sabberworm\CSS\RuleSet\RuleSet
@@ -17,13 +19,13 @@ final class RuleSetTest extends TestCase
17
19
use RuleContainerTest;
18
20
19
21
/**
20
- * @var ConcreteRuleSet
22
+ * @var RuleSet
21
23
*/
22
24
private $ subject ;
23
25
24
26
protected function setUp (): void
25
27
{
26
- $ this ->subject = new ConcreteRuleSet ();
28
+ $ this ->subject = new RuleSet ();
27
29
}
28
30
29
31
/**
@@ -41,4 +43,59 @@ public function implementsCSSListItem(): void
41
43
{
42
44
self ::assertInstanceOf (CSSListItem::class, $ this ->subject );
43
45
}
46
+
47
+ /**
48
+ * @return array<string, array{0: list<array{name: string, value: string}>, 1: string}>
49
+ */
50
+ public static function providePropertyNamesAndValuesAndExpectedCss (): array
51
+ {
52
+ return [
53
+ 'no properties ' => [[], '' ],
54
+ 'one property ' => [
55
+ [['name ' => 'color ' , 'value ' => 'green ' ]],
56
+ 'color: green; ' ,
57
+ ],
58
+ 'two different properties ' => [
59
+ [
60
+ ['name ' => 'color ' , 'value ' => 'green ' ],
61
+ ['name ' => 'display ' , 'value ' => 'block ' ],
62
+ ],
63
+ 'color: green;display: block; ' ,
64
+ ],
65
+ 'two of the same property ' => [
66
+ [
67
+ ['name ' => 'color ' , 'value ' => '#40A040 ' ],
68
+ ['name ' => 'color ' , 'value ' => 'rgba(0, 128, 0, 0.25) ' ],
69
+ ],
70
+ 'color: #40A040;color: rgba(0, 128, 0, 0.25); ' ,
71
+ ],
72
+ ];
73
+ }
74
+
75
+ /**
76
+ * @test
77
+ *
78
+ * @param list<array{name: string, value: string}> $propertyNamesAndValuesToSet
79
+ *
80
+ * @dataProvider providePropertyNamesAndValuesAndExpectedCss
81
+ */
82
+ public function renderReturnsCssForRulesSet (array $ propertyNamesAndValuesToSet , string $ expectedCss ): void
83
+ {
84
+ $ rulesToSet = \array_map (
85
+ /**
86
+ * @param array{name: string, value: string} $nameAndValue
87
+ */
88
+ static function (array $ nameAndValue ): Rule {
89
+ $ rule = new Rule ($ nameAndValue ['name ' ]);
90
+ $ rule ->setValue ($ nameAndValue ['value ' ]);
91
+ return $ rule ;
92
+ },
93
+ $ propertyNamesAndValuesToSet
94
+ );
95
+ $ this ->subject ->setRules ($ rulesToSet );
96
+
97
+ $ result = $ this ->subject ->render (OutputFormat::create ());
98
+
99
+ self ::assertSame ($ expectedCss , $ result );
100
+ }
44
101
}
0 commit comments