7
7
use PHPUnit \Framework \TestCase ;
8
8
use Sabberworm \CSS \CSSElement ;
9
9
use Sabberworm \CSS \Rule \Rule ;
10
+ use Sabberworm \CSS \RuleSet \RuleSet ;
10
11
use Sabberworm \CSS \Tests \Unit \RuleSet \Fixtures \ConcreteRuleSet ;
11
12
12
13
/**
@@ -27,38 +28,38 @@ public function implementsCSSElement()
27
28
}
28
29
29
30
/**
30
- * @return array<string, array{0: list<Rule >, 1: string, 2: list<string>}>
31
+ * @return array<string, array{0: list<string >, 1: string, 2: list<string>}>
31
32
*/
32
- public static function provideRulesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames ()
33
+ public static function providePropertyNamesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames ()
33
34
{
34
35
return [
35
36
'removing single rule ' => [
36
- [new Rule ( 'color ' ) ],
37
+ ['color ' ],
37
38
'color ' ,
38
39
[],
39
40
],
40
41
'removing first rule ' => [
41
- [new Rule ( 'color ' ), new Rule ( 'display ' ) ],
42
+ ['color ' , 'display ' ],
42
43
'color ' ,
43
44
['display ' ],
44
45
],
45
46
'removing last rule ' => [
46
- [new Rule ( 'color ' ), new Rule ( 'display ' ) ],
47
+ ['color ' , 'display ' ],
47
48
'display ' ,
48
49
['color ' ],
49
50
],
50
51
'removing middle rule ' => [
51
- [new Rule ( 'color ' ), new Rule ( 'display ' ), new Rule ( 'width ' ) ],
52
+ ['color ' , 'display ' , 'width ' ],
52
53
'display ' ,
53
54
['color ' , 'width ' ],
54
55
],
55
56
'removing multiple rules ' => [
56
- [new Rule ( 'color ' ), new Rule ( 'color ' ) ],
57
+ ['color ' , 'color ' ],
57
58
'color ' ,
58
59
[],
59
60
],
60
61
'removing multiple rules with another kept ' => [
61
- [new Rule ( 'color ' ), new Rule ( 'color ' ), new Rule ( 'display ' ) ],
62
+ ['color ' , 'color ' , 'display ' ],
62
63
'color ' ,
63
64
['display ' ],
64
65
],
@@ -68,7 +69,7 @@ public static function provideRulesAndPropertyNameToRemoveAndExpectedRemainingPr
68
69
[],
69
70
],
70
71
'removing nonexistent rule from nonempty list ' => [
71
- [new Rule ( 'color ' ), new Rule ( 'display ' ) ],
72
+ ['color ' , 'display ' ],
72
73
'width ' ,
73
74
['color ' , 'display ' ],
74
75
],
@@ -78,62 +79,62 @@ public static function provideRulesAndPropertyNameToRemoveAndExpectedRemainingPr
78
79
/**
79
80
* @test
80
81
*
81
- * @param list<Rule > $rules
82
- * @param string $propertyName
82
+ * @param list<string > $initialPropertyNames
83
+ * @param string $propertyNameToRemove
83
84
* @param list<string> $expectedRemainingPropertyNames
84
85
*
85
- * @dataProvider provideRulesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames
86
+ * @dataProvider providePropertyNamesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames
86
87
*/
87
88
public function removeMatchingRulesRemovesRulesByPropertyNameAndKeepsOthers (
88
- array $ rules ,
89
- $ propertyName ,
89
+ array $ initialPropertyNames ,
90
+ $ propertyNameToRemove ,
90
91
array $ expectedRemainingPropertyNames
91
92
) {
92
93
$ subject = new ConcreteRuleSet ();
93
- $ subject-> setRules ( $ rules );
94
+ self :: setRulesFromPropertyNames ( $ subject, $ initialPropertyNames );
94
95
95
- $ subject ->removeMatchingRules ($ propertyName );
96
+ $ subject ->removeMatchingRules ($ propertyNameToRemove );
96
97
97
98
$ remainingRules = $ subject ->getRulesAssoc ();
98
- self ::assertArrayNotHasKey ($ propertyName , $ remainingRules );
99
+ self ::assertArrayNotHasKey ($ propertyNameToRemove , $ remainingRules );
99
100
foreach ($ expectedRemainingPropertyNames as $ expectedPropertyName ) {
100
101
self ::assertArrayHasKey ($ expectedPropertyName , $ remainingRules );
101
102
}
102
103
}
103
104
104
105
/**
105
- * @return array<string, array{0: list<Rule >, 1: string, 2: list<string>}>
106
+ * @return array<string, array{0: list<string >, 1: string, 2: list<string>}>
106
107
*/
107
- public static function provideRulesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames ()
108
+ public static function providePropertyNamesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames ()
108
109
{
109
110
return [
110
111
'removing shorthand rule ' => [
111
- [new Rule ( 'font ' ) ],
112
+ ['font ' ],
112
113
'font ' ,
113
114
[],
114
115
],
115
116
'removing longhand rule ' => [
116
- [new Rule ( 'font-size ' ) ],
117
+ ['font-size ' ],
117
118
'font ' ,
118
119
[],
119
120
],
120
121
'removing shorthand and longhand rule ' => [
121
- [new Rule ( 'font ' ), new Rule ( 'font-size ' ) ],
122
+ ['font ' , 'font-size ' ],
122
123
'font ' ,
123
124
[],
124
125
],
125
126
'removing shorthand rule with another kept ' => [
126
- [new Rule ( 'font ' ), new Rule ( 'color ' ) ],
127
+ ['font ' , 'color ' ],
127
128
'font ' ,
128
129
['color ' ],
129
130
],
130
131
'removing longhand rule with another kept ' => [
131
- [new Rule ( 'font-size ' ), new Rule ( 'color ' ) ],
132
+ ['font-size ' , 'color ' ],
132
133
'font ' ,
133
134
['color ' ],
134
135
],
135
136
'keeping other rules whose property names begin with the same characters ' => [
136
- [new Rule ( 'contain ' ), new Rule ( 'container ' ), new Rule ( 'container-type ' ) ],
137
+ ['contain ' , 'container ' , 'container-type ' ],
137
138
'contain ' ,
138
139
['container ' , 'container-type ' ],
139
140
],
@@ -143,20 +144,20 @@ public static function provideRulesAndPropertyNamePrefixToRemoveAndExpectedRemai
143
144
/**
144
145
* @test
145
146
*
146
- * @param list<Rule > $rules
147
+ * @param list<string > $initialPropertyNames
147
148
* @param string $propertyNamePrefix
148
149
* @param list<string> $expectedRemainingPropertyNames
149
150
*
150
- * @dataProvider provideRulesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames
151
+ * @dataProvider providePropertyNamesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames
151
152
*/
152
153
public function removeMatchingRulesRemovesRulesByPropertyNamePrefixAndKeepsOthers (
153
- array $ rules ,
154
+ array $ initialPropertyNames ,
154
155
$ propertyNamePrefix ,
155
156
array $ expectedRemainingPropertyNames
156
157
) {
157
158
$ propertyNamePrefixWithHyphen = $ propertyNamePrefix . '- ' ;
158
159
$ subject = new ConcreteRuleSet ();
159
- $ subject-> setRules ( $ rules );
160
+ self :: setRulesFromPropertyNames ( $ subject, $ initialPropertyNames );
160
161
161
162
$ subject ->removeMatchingRules ($ propertyNamePrefixWithHyphen );
162
163
@@ -171,32 +172,45 @@ public function removeMatchingRulesRemovesRulesByPropertyNamePrefixAndKeepsOther
171
172
}
172
173
173
174
/**
174
- * @return array<string, array{0: list<Rule >}>
175
+ * @return array<string, array{0: list<string >}>
175
176
*/
176
- public static function provideRulesToRemove ()
177
+ public static function providePropertyNamesToRemove ()
177
178
{
178
179
return [
179
- 'no rules ' => [[]],
180
- 'one rule ' => [[new Rule ( 'color ' ) ]],
181
- 'two rules for different properties ' => [[new Rule ( 'color ' ), new Rule ( 'display ' ) ]],
182
- 'two rules for the same property ' => [[new Rule ( 'color ' ), new Rule ( 'color ' ) ]],
180
+ 'no properties ' => [[]],
181
+ 'one property ' => [['color ' ]],
182
+ 'two different properties ' => [['color ' , 'display ' ]],
183
+ 'two of the same property ' => [['color ' , 'color ' ]],
183
184
];
184
185
}
185
186
186
187
/**
187
188
* @test
188
189
*
189
- * @param list<Rule > $rules
190
+ * @param list<string > $propertyNamesToRemove
190
191
*
191
- * @dataProvider provideRulesToRemove
192
+ * @dataProvider providePropertyNamesToRemove
192
193
*/
193
- public function removeAllRulesRemovesAllRules (array $ rules )
194
+ public function removeAllRulesRemovesAllRules (array $ propertyNamesToRemove )
194
195
{
195
196
$ subject = new ConcreteRuleSet ();
196
- $ subject-> setRules ( $ rules );
197
+ self :: setRulesFromPropertyNames ( $ subject, $ propertyNamesToRemove );
197
198
198
199
$ subject ->removeAllRules ();
199
200
200
201
self ::assertSame ([], $ subject ->getRules ());
201
202
}
203
+
204
+ /**
205
+ * @param list<string> $propertyNames
206
+ */
207
+ private static function setRulesFromPropertyNames (RuleSet $ subject , array $ propertyNames )
208
+ {
209
+ $ subject ->setRules (\array_map (
210
+ function (string $ propertyName ) {
211
+ return new Rule ($ propertyName );
212
+ },
213
+ $ propertyNames
214
+ ));
215
+ }
202
216
}
0 commit comments