@@ -67,7 +67,7 @@ public static function providePropertyNamesToBeSetInitially(): array
67
67
/**
68
68
* @return array<string, array{0: non-empty-string}>
69
69
*/
70
- public static function providePropertyNameToAdd (): array
70
+ public static function provideAnotherPropertyName (): array
71
71
{
72
72
return [
73
73
'property name `color` maybe matching that of existing declaration ' => ['color ' ],
@@ -79,17 +79,17 @@ public static function providePropertyNameToAdd(): array
79
79
/**
80
80
* @return DataProvider<string, array{0: list<string>, 1: string}>
81
81
*/
82
- public static function provideInitialPropertyNamesAndPropertyNameToAdd (): DataProvider
82
+ public static function provideInitialPropertyNamesAndAnotherPropertyName (): DataProvider
83
83
{
84
- return DataProvider::cross (self ::providePropertyNamesToBeSetInitially (), self ::providePropertyNameToAdd ());
84
+ return DataProvider::cross (self ::providePropertyNamesToBeSetInitially (), self ::provideAnotherPropertyName ());
85
85
}
86
86
87
87
/**
88
88
* @test
89
89
*
90
90
* @param list<string> $initialPropertyNames
91
91
*
92
- * @dataProvider provideInitialPropertyNamesAndPropertyNameToAdd
92
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
93
93
*/
94
94
public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAndColumnNumbers (
95
95
array $ initialPropertyNames ,
@@ -111,7 +111,7 @@ public function addRuleWithoutSiblingAddsRuleAfterInitialRulesAndSetsValidLineAn
111
111
/**
112
112
* @test
113
113
*
114
- * @dataProvider provideInitialPropertyNamesAndPropertyNameToAdd
114
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
115
115
*
116
116
* @param list<string> $initialPropertyNames
117
117
*/
@@ -134,7 +134,7 @@ public function addRuleWithOnlyLineNumberAddsRuleAndSetsColumnNumberPreservingLi
134
134
/**
135
135
* @test
136
136
*
137
- * @dataProvider provideInitialPropertyNamesAndPropertyNameToAdd
137
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
138
138
*
139
139
* @param list<string> $initialPropertyNames
140
140
*/
@@ -158,7 +158,7 @@ public function addRuleWithOnlyColumnNumberAddsRuleAfterInitialRulesAndSetsLineN
158
158
/**
159
159
* @test
160
160
*
161
- * @dataProvider provideInitialPropertyNamesAndPropertyNameToAdd
161
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
162
162
*
163
163
* @param list<string> $initialPropertyNames
164
164
*/
@@ -180,21 +180,21 @@ public function addRuleWithCompletePositionAddsRuleAndPreservesPosition(
180
180
/**
181
181
* @return array<string, array{0: non-empty-list<non-empty-string>, 1: int<0, max>}>
182
182
*/
183
- public static function provideInitialPropertyNamesAndSiblingIndex (): array
183
+ public static function provideInitialPropertyNamesAndIndexOfOne (): array
184
184
{
185
185
$ initialPropertyNamesSets = self ::providePropertyNamesToBeSetInitially ();
186
186
187
- // Provide sets with each possible sibling index for the initially set `Rule`s.
188
- $ initialPropertyNamesAndSiblingIndexSets = [];
187
+ // Provide sets with each possible index for the initially set `Rule`s.
188
+ $ initialPropertyNamesAndIndexSets = [];
189
189
foreach ($ initialPropertyNamesSets as $ setName => $ data ) {
190
190
$ initialPropertyNames = $ data [0 ];
191
- for ($ siblingIndex = 0 ; $ siblingIndex < \count ($ initialPropertyNames ); ++$ siblingIndex ) {
192
- $ initialPropertyNamesAndSiblingIndexSets [$ setName . ', sibling index ' . $ siblingIndex ] =
193
- [$ initialPropertyNames , $ siblingIndex ];
191
+ for ($ index = 0 ; $ index < \count ($ initialPropertyNames ); ++$ index ) {
192
+ $ initialPropertyNamesAndIndexSets [$ setName . ', index ' . $ index ] =
193
+ [$ initialPropertyNames , $ index ];
194
194
}
195
195
}
196
196
197
- return $ initialPropertyNamesAndSiblingIndexSets ;
197
+ return $ initialPropertyNamesAndIndexSets ;
198
198
}
199
199
200
200
/**
@@ -203,15 +203,15 @@ public static function provideInitialPropertyNamesAndSiblingIndex(): array
203
203
public static function provideInitialPropertyNamesAndSiblingIndexAndPropertyNameToAdd (): DataProvider
204
204
{
205
205
return DataProvider::cross (
206
- self ::provideInitialPropertyNamesAndSiblingIndex (),
207
- self ::providePropertyNameToAdd ()
206
+ self ::provideInitialPropertyNamesAndIndexOfOne (),
207
+ self ::provideAnotherPropertyName ()
208
208
);
209
209
}
210
210
211
211
/**
212
212
* @test
213
213
*
214
- * @param list<string> $initialPropertyNames
214
+ * @param non-empty- list<string> $initialPropertyNames
215
215
* @param int<0, max> $siblingIndex
216
216
*
217
217
* @dataProvider provideInitialPropertyNamesAndSiblingIndexAndPropertyNameToAdd
@@ -236,7 +236,7 @@ public function addRuleWithSiblingInsertsRuleBeforeSibling(
236
236
/**
237
237
* @test
238
238
*
239
- * @param list<string> $initialPropertyNames
239
+ * @param non-empty- list<string> $initialPropertyNames
240
240
* @param int<0, max> $siblingIndex
241
241
*
242
242
* @dataProvider provideInitialPropertyNamesAndSiblingIndexAndPropertyNameToAdd
@@ -259,7 +259,7 @@ public function addRuleWithSiblingSetsValidLineNumber(
259
259
/**
260
260
* @test
261
261
*
262
- * @param list<string> $initialPropertyNames
262
+ * @param non-empty- list<string> $initialPropertyNames
263
263
* @param int<0, max> $siblingIndex
264
264
*
265
265
* @dataProvider provideInitialPropertyNamesAndSiblingIndexAndPropertyNameToAdd
@@ -284,7 +284,7 @@ public function addRuleWithSiblingSetsValidColumnNumber(
284
284
*
285
285
* @param list<string> $initialPropertyNames
286
286
*
287
- * @dataProvider provideInitialPropertyNamesAndPropertyNameToAdd
287
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
288
288
*/
289
289
public function addRuleWithSiblingNotInRuleSetAddsRuleAfterInitialRulesAndSetsValidLineAndColumnNumbers (
290
290
array $ initialPropertyNames ,
@@ -305,6 +305,46 @@ public function addRuleWithSiblingNotInRuleSetAddsRuleAfterInitialRulesAndSetsVa
305
305
self ::assertGreaterThanOrEqual (0 , $ ruleToAdd ->getColumnNumber (), 'column number not valid ' );
306
306
}
307
307
308
+ /**
309
+ * @test
310
+ *
311
+ * @param non-empty-list<string> $initialPropertyNames
312
+ * @param int<0, max> $indexToRemove
313
+ *
314
+ * @dataProvider provideInitialPropertyNamesAndIndexOfOne
315
+ */
316
+ public function removeRuleRemovesRuleInSetAndKeepsOthers (array $ initialPropertyNames , int $ indexToRemove ): void
317
+ {
318
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
319
+ $ ruleToRemove = $ this ->subject ->getRules ()[$ indexToRemove ];
320
+
321
+ $ this ->subject ->removeRule ($ ruleToRemove );
322
+
323
+ $ remainingRules = $ this ->subject ->getRules ();
324
+ self ::assertNotContains ($ ruleToRemove , $ remainingRules );
325
+ self ::assertCount (\count ($ initialPropertyNames ) - 1 , $ remainingRules );
326
+ }
327
+
328
+ /**
329
+ * @test
330
+ *
331
+ * @param list<string> $initialPropertyNames
332
+ *
333
+ * @dataProvider provideInitialPropertyNamesAndAnotherPropertyName
334
+ */
335
+ public function removeRuleDoesNothingWithRuleNotInSet (
336
+ array $ initialPropertyNames ,
337
+ string $ propertyNameToRemove
338
+ ): void {
339
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
340
+ $ initialRules = $ this ->subject ->getRules ();
341
+ $ ruleToRemove = new Rule ($ propertyNameToRemove );
342
+
343
+ $ this ->subject ->removeRule ($ ruleToRemove );
344
+
345
+ self ::assertSame ($ initialRules , $ this ->subject ->getRules ());
346
+ }
347
+
308
348
/**
309
349
* @return array<string, array{0: list<string>, 1: string, 2: list<string>}>
310
350
*/
0 commit comments