77use PHPUnit \Framework \TestCase ;
88use Sabberworm \CSS \CSSElement ;
99use 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 ;
1113
1214/**
1315 * @covers \Sabberworm\CSS\RuleSet\RuleSet
@@ -17,13 +19,13 @@ final class RuleSetTest extends TestCase
1719 use RuleContainerTest;
1820
1921 /**
20- * @var ConcreteRuleSet
22+ * @var RuleSet
2123 */
2224 private $ subject ;
2325
2426 protected function setUp (): void
2527 {
26- $ this ->subject = new ConcreteRuleSet ();
28+ $ this ->subject = new RuleSet ();
2729 }
2830
2931 /**
@@ -41,4 +43,59 @@ public function implementsCSSListItem(): void
4143 {
4244 self ::assertInstanceOf (CSSListItem::class, $ this ->subject );
4345 }
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+ }
44101}
0 commit comments