@@ -91,7 +91,7 @@ public static function provideInitialPropertyNamesAndAnotherPropertyName(): Data
91
91
*
92
92
* @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
93
93
*/
94
- public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAndColumnNumbers (
94
+ public function addRuleWithoutPositionWithoutSiblingAddsRuleAfterInitialRules (
95
95
array $ initialPropertyNames ,
96
96
string $ propertyNameToAdd
97
97
): void {
@@ -102,8 +102,44 @@ public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAn
102
102
103
103
$ rules = $ this ->subject ->getRules ();
104
104
self ::assertSame ($ ruleToAdd , \end ($ rules ));
105
+ }
106
+
107
+ /**
108
+ * @test
109
+ *
110
+ * @param list<string> $initialPropertyNames
111
+ *
112
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
113
+ */
114
+ public function addRuleWithoutPositionWithoutSiblingSetsValidLineNumber (
115
+ array $ initialPropertyNames ,
116
+ string $ propertyNameToAdd
117
+ ): void {
118
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
119
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
120
+
121
+ $ this ->subject ->addRule ($ ruleToAdd );
122
+
105
123
self ::assertIsInt ($ ruleToAdd ->getLineNumber (), 'line number not set ' );
106
124
self ::assertGreaterThanOrEqual (1 , $ ruleToAdd ->getLineNumber (), 'line number not valid ' );
125
+ }
126
+
127
+ /**
128
+ * @test
129
+ *
130
+ * @param list<string> $initialPropertyNames
131
+ *
132
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
133
+ */
134
+ public function addRuleWithoutPositionWithoutSiblingSetsValidColumnNumber (
135
+ array $ initialPropertyNames ,
136
+ string $ propertyNameToAdd
137
+ ): void {
138
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
139
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
140
+
141
+ $ this ->subject ->addRule ($ ruleToAdd );
142
+
107
143
self ::assertIsInt ($ ruleToAdd ->getColumnNumber (), 'column number not set ' );
108
144
self ::assertGreaterThanOrEqual (0 , $ ruleToAdd ->getColumnNumber (), 'column number not valid ' );
109
145
}
@@ -115,7 +151,7 @@ public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAn
115
151
*
116
152
* @param list<string> $initialPropertyNames
117
153
*/
118
- public function addRuleWithOnlyLineNumberAddsRuleAndSetsColumnNumberPreservingLineNumber (
154
+ public function addRuleWithOnlyLineNumberWithoutSiblingAddsRule (
119
155
array $ initialPropertyNames ,
120
156
string $ propertyNameToAdd
121
157
): void {
@@ -126,8 +162,46 @@ public function addRuleWithOnlyLineNumberAddsRuleAndSetsColumnNumberPreservingLi
126
162
$ this ->subject ->addRule ($ ruleToAdd );
127
163
128
164
self ::assertContains ($ ruleToAdd , $ this ->subject ->getRules ());
165
+ }
166
+
167
+ /**
168
+ * @test
169
+ *
170
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
171
+ *
172
+ * @param list<string> $initialPropertyNames
173
+ */
174
+ public function addRuleWithOnlyLineNumberWithoutSiblingSetsColumnNumber (
175
+ array $ initialPropertyNames ,
176
+ string $ propertyNameToAdd
177
+ ): void {
178
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
179
+ $ ruleToAdd ->setPosition (42 );
180
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
181
+
182
+ $ this ->subject ->addRule ($ ruleToAdd );
183
+
129
184
self ::assertIsInt ($ ruleToAdd ->getColumnNumber (), 'column number not set ' );
130
185
self ::assertGreaterThanOrEqual (0 , $ ruleToAdd ->getColumnNumber (), 'column number not valid ' );
186
+ }
187
+
188
+ /**
189
+ * @test
190
+ *
191
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
192
+ *
193
+ * @param list<string> $initialPropertyNames
194
+ */
195
+ public function addRuleWithOnlyLineNumberWithoutSiblingPreservesLineNumber (
196
+ array $ initialPropertyNames ,
197
+ string $ propertyNameToAdd
198
+ ): void {
199
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
200
+ $ ruleToAdd ->setPosition (42 );
201
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
202
+
203
+ $ this ->subject ->addRule ($ ruleToAdd );
204
+
131
205
self ::assertSame (42 , $ ruleToAdd ->getLineNumber (), 'line number not preserved ' );
132
206
}
133
207
@@ -138,7 +212,7 @@ public function addRuleWithOnlyLineNumberAddsRuleAndSetsColumnNumberPreservingLi
138
212
*
139
213
* @param list<string> $initialPropertyNames
140
214
*/
141
- public function addRuleWithOnlyColumnNumberAddsRuleAfterInitialRulesAndSetsLineNumberPreservingColumnNumber (
215
+ public function addRuleWithOnlyColumnNumberWithoutSiblingAddsRuleAfterInitialRules (
142
216
array $ initialPropertyNames ,
143
217
string $ propertyNameToAdd
144
218
): void {
@@ -150,8 +224,46 @@ public function addRuleWithOnlyColumnNumberAddsRuleAfterInitialRulesAndSetsLineN
150
224
151
225
$ rules = $ this ->subject ->getRules ();
152
226
self ::assertSame ($ ruleToAdd , \end ($ rules ));
227
+ }
228
+
229
+ /**
230
+ * @test
231
+ *
232
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
233
+ *
234
+ * @param list<string> $initialPropertyNames
235
+ */
236
+ public function addRuleWithOnlyColumnNumberWithoutSiblingSetsLineNumber (
237
+ array $ initialPropertyNames ,
238
+ string $ propertyNameToAdd
239
+ ): void {
240
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
241
+ $ ruleToAdd ->setPosition (null , 42 );
242
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
243
+
244
+ $ this ->subject ->addRule ($ ruleToAdd );
245
+
153
246
self ::assertIsInt ($ ruleToAdd ->getLineNumber (), 'line number not set ' );
154
247
self ::assertGreaterThanOrEqual (1 , $ ruleToAdd ->getLineNumber (), 'line number not valid ' );
248
+ }
249
+
250
+ /**
251
+ * @test
252
+ *
253
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
254
+ *
255
+ * @param list<string> $initialPropertyNames
256
+ */
257
+ public function addRuleWithOnlyColumnNumberWithoutSiblingPreservesColumnNumber (
258
+ array $ initialPropertyNames ,
259
+ string $ propertyNameToAdd
260
+ ): void {
261
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
262
+ $ ruleToAdd ->setPosition (null , 42 );
263
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
264
+
265
+ $ this ->subject ->addRule ($ ruleToAdd );
266
+
155
267
self ::assertSame (42 , $ ruleToAdd ->getColumnNumber (), 'column number not preserved ' );
156
268
}
157
269
@@ -162,7 +274,7 @@ public function addRuleWithOnlyColumnNumberAddsRuleAfterInitialRulesAndSetsLineN
162
274
*
163
275
* @param list<string> $initialPropertyNames
164
276
*/
165
- public function addRuleWithCompletePositionAddsRuleAndPreservesPosition (
277
+ public function addRuleWithCompletePositionWithoutSiblingAddsRule (
166
278
array $ initialPropertyNames ,
167
279
string $ propertyNameToAdd
168
280
): void {
@@ -173,6 +285,25 @@ public function addRuleWithCompletePositionAddsRuleAndPreservesPosition(
173
285
$ this ->subject ->addRule ($ ruleToAdd );
174
286
175
287
self ::assertContains ($ ruleToAdd , $ this ->subject ->getRules ());
288
+ }
289
+
290
+ /**
291
+ * @test
292
+ *
293
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
294
+ *
295
+ * @param list<string> $initialPropertyNames
296
+ */
297
+ public function addRuleWithCompletePositionWithoutSiblingPreservesPosition (
298
+ array $ initialPropertyNames ,
299
+ string $ propertyNameToAdd
300
+ ): void {
301
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
302
+ $ ruleToAdd ->setPosition (42 , 64 );
303
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
304
+
305
+ $ this ->subject ->addRule ($ ruleToAdd );
306
+
176
307
self ::assertSame (42 , $ ruleToAdd ->getLineNumber (), 'line number not preserved ' );
177
308
self ::assertSame (64 , $ ruleToAdd ->getColumnNumber (), 'column number not preserved ' );
178
309
}
@@ -286,7 +417,7 @@ public function addRuleWithSiblingSetsValidColumnNumber(
286
417
*
287
418
* @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
288
419
*/
289
- public function addRuleWithSiblingNotInRuleSetAddsRuleAfterInitialRulesAndSetsValidLineAndColumnNumbers (
420
+ public function addRuleWithSiblingNotInSetAddsRuleAfterInitialRules (
290
421
array $ initialPropertyNames ,
291
422
string $ propertyNameToAdd
292
423
): void {
@@ -299,8 +430,48 @@ public function addRuleWithSiblingNotInRuleSetAddsRuleAfterInitialRulesAndSetsVa
299
430
300
431
$ rules = $ this ->subject ->getRules ();
301
432
self ::assertSame ($ ruleToAdd , \end ($ rules ));
433
+ }
434
+
435
+ /**
436
+ * @test
437
+ *
438
+ * @param list<string> $initialPropertyNames
439
+ *
440
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
441
+ */
442
+ public function addRuleWithSiblingNotInSetSetsValidLineNumber (
443
+ array $ initialPropertyNames ,
444
+ string $ propertyNameToAdd
445
+ ): void {
446
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
447
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
448
+
449
+ // `display` is sometimes in `$initialPropertyNames` and sometimes the `$propertyNameToAdd`.
450
+ // Choosing this for the bogus sibling allows testing all combinations of whether it is or isn't.
451
+ $ this ->subject ->addRule ($ ruleToAdd , new Rule ('display ' ));
452
+
302
453
self ::assertIsInt ($ ruleToAdd ->getLineNumber (), 'line number not set ' );
303
454
self ::assertGreaterThanOrEqual (1 , $ ruleToAdd ->getLineNumber (), 'line number not valid ' );
455
+ }
456
+
457
+ /**
458
+ * @test
459
+ *
460
+ * @param list<string> $initialPropertyNames
461
+ *
462
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
463
+ */
464
+ public function addRuleWithSiblingNotInSetSetsValidColumnNumber (
465
+ array $ initialPropertyNames ,
466
+ string $ propertyNameToAdd
467
+ ): void {
468
+ $ ruleToAdd = new Rule ($ propertyNameToAdd );
469
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
470
+
471
+ // `display` is sometimes in `$initialPropertyNames` and sometimes the `$propertyNameToAdd`.
472
+ // Choosing this for the bogus sibling allows testing all combinations of whether it is or isn't.
473
+ $ this ->subject ->addRule ($ ruleToAdd , new Rule ('display ' ));
474
+
304
475
self ::assertIsInt ($ ruleToAdd ->getColumnNumber (), 'column number not set ' );
305
476
self ::assertGreaterThanOrEqual (0 , $ ruleToAdd ->getColumnNumber (), 'column number not valid ' );
306
477
}
@@ -410,6 +581,24 @@ public static function providePropertyNamesAndPropertyNameToRemoveAndExpectedRem
410
581
];
411
582
}
412
583
584
+ /**
585
+ * @test
586
+ *
587
+ * @param list<string> $initialPropertyNames
588
+ *
589
+ * @dataProvider providePropertyNamesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames
590
+ */
591
+ public function removeMatchingRulesRemovesRulesWithPropertyName (
592
+ array $ initialPropertyNames ,
593
+ string $ propertyNameToRemove
594
+ ): void {
595
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
596
+
597
+ $ this ->subject ->removeMatchingRules ($ propertyNameToRemove );
598
+
599
+ self ::assertArrayNotHasKey ($ propertyNameToRemove , $ this ->subject ->getRulesAssoc ());
600
+ }
601
+
413
602
/**
414
603
* @test
415
604
*
@@ -418,7 +607,7 @@ public static function providePropertyNamesAndPropertyNameToRemoveAndExpectedRem
418
607
*
419
608
* @dataProvider providePropertyNamesAndPropertyNameToRemoveAndExpectedRemainingPropertyNames
420
609
*/
421
- public function removeMatchingRulesRemovesRulesByPropertyNameAndKeepsOthers (
610
+ public function removeMatchingRulesWithPropertyNameKeepsOtherRules (
422
611
array $ initialPropertyNames ,
423
612
string $ propertyNameToRemove ,
424
613
array $ expectedRemainingPropertyNames
@@ -428,7 +617,9 @@ public function removeMatchingRulesRemovesRulesByPropertyNameAndKeepsOthers(
428
617
$ this ->subject ->removeMatchingRules ($ propertyNameToRemove );
429
618
430
619
$ remainingRules = $ this ->subject ->getRulesAssoc ();
431
- self ::assertArrayNotHasKey ($ propertyNameToRemove , $ remainingRules );
620
+ if ($ expectedRemainingPropertyNames === []) {
621
+ self ::assertSame ([], $ remainingRules );
622
+ }
432
623
foreach ($ expectedRemainingPropertyNames as $ expectedPropertyName ) {
433
624
self ::assertArrayHasKey ($ expectedPropertyName , $ remainingRules );
434
625
}
@@ -477,14 +668,12 @@ public static function providePropertyNamesAndPropertyNamePrefixToRemoveAndExpec
477
668
* @test
478
669
*
479
670
* @param list<string> $initialPropertyNames
480
- * @param list<string> $expectedRemainingPropertyNames
481
671
*
482
672
* @dataProvider providePropertyNamesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames
483
673
*/
484
- public function removeMatchingRulesRemovesRulesByPropertyNamePrefixAndKeepsOthers (
674
+ public function removeMatchingRulesRemovesRulesWithPropertyNamePrefix (
485
675
array $ initialPropertyNames ,
486
- string $ propertyNamePrefix ,
487
- array $ expectedRemainingPropertyNames
676
+ string $ propertyNamePrefix
488
677
): void {
489
678
$ propertyNamePrefixWithHyphen = $ propertyNamePrefix . '- ' ;
490
679
$ this ->setRulesFromPropertyNames ($ initialPropertyNames );
@@ -496,6 +685,30 @@ public function removeMatchingRulesRemovesRulesByPropertyNamePrefixAndKeepsOther
496
685
foreach (\array_keys ($ remainingRules ) as $ remainingPropertyName ) {
497
686
self ::assertStringStartsNotWith ($ propertyNamePrefixWithHyphen , $ remainingPropertyName );
498
687
}
688
+ }
689
+
690
+ /**
691
+ * @test
692
+ *
693
+ * @param list<string> $initialPropertyNames
694
+ * @param list<string> $expectedRemainingPropertyNames
695
+ *
696
+ * @dataProvider providePropertyNamesAndPropertyNamePrefixToRemoveAndExpectedRemainingPropertyNames
697
+ */
698
+ public function removeMatchingRulesWithPropertyNamePrefixKeepsOtherRules (
699
+ array $ initialPropertyNames ,
700
+ string $ propertyNamePrefix ,
701
+ array $ expectedRemainingPropertyNames
702
+ ): void {
703
+ $ propertyNamePrefixWithHyphen = $ propertyNamePrefix . '- ' ;
704
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
705
+
706
+ $ this ->subject ->removeMatchingRules ($ propertyNamePrefixWithHyphen );
707
+
708
+ $ remainingRules = $ this ->subject ->getRulesAssoc ();
709
+ if ($ expectedRemainingPropertyNames === []) {
710
+ self ::assertSame ([], $ remainingRules );
711
+ }
499
712
foreach ($ expectedRemainingPropertyNames as $ expectedPropertyName ) {
500
713
self ::assertArrayHasKey ($ expectedPropertyName , $ remainingRules );
501
714
}
0 commit comments