@@ -54,7 +54,7 @@ public function implementsRuleContainer(): void
54
54
/**
55
55
* @return array<string, array{0: list<non-empty-string>}>
56
56
*/
57
- public static function providePropertyNamesToBeSetInitially (): array
57
+ public static function providePropertyNames (): array
58
58
{
59
59
return [
60
60
'no properties ' => [[]],
@@ -81,7 +81,7 @@ public static function provideAnotherPropertyName(): array
81
81
*/
82
82
public static function provideInitialPropertyNamesAndAnotherPropertyName (): DataProvider
83
83
{
84
- return DataProvider::cross (self ::providePropertyNamesToBeSetInitially (), self ::provideAnotherPropertyName ());
84
+ return DataProvider::cross (self ::providePropertyNames (), self ::provideAnotherPropertyName ());
85
85
}
86
86
87
87
/**
@@ -313,7 +313,7 @@ public function addRuleWithCompletePositionWithoutSiblingPreservesPosition(
313
313
*/
314
314
public static function provideInitialPropertyNamesAndIndexOfOne (): array
315
315
{
316
- $ initialPropertyNamesSets = self ::providePropertyNamesToBeSetInitially ();
316
+ $ initialPropertyNamesSets = self ::providePropertyNames ();
317
317
318
318
// Provide sets with each possible index for the initially set `Rule`s.
319
319
$ initialPropertyNamesAndIndexSets = [];
@@ -719,7 +719,7 @@ public function removeMatchingRulesWithPropertyNamePrefixKeepsOtherRules(
719
719
*
720
720
* @param list<string> $propertyNamesToRemove
721
721
*
722
- * @dataProvider providePropertyNamesToBeSetInitially
722
+ * @dataProvider providePropertyNames
723
723
*/
724
724
public function removeAllRulesRemovesAllRules (array $ propertyNamesToRemove ): void
725
725
{
@@ -730,16 +730,162 @@ public function removeAllRulesRemovesAllRules(array $propertyNamesToRemove): voi
730
730
self ::assertSame ([], $ this ->subject ->getRules ());
731
731
}
732
732
733
+ /**
734
+ * @test
735
+ *
736
+ * @param list<string> $propertyNamesToSet
737
+ *
738
+ * @dataProvider providePropertyNames
739
+ */
740
+ public function setRulesOnVirginSetsRulesWithoutPositionInOrder (array $ propertyNamesToSet ): void
741
+ {
742
+ $ rulesToSet = self ::createRulesFromPropertyNames ($ propertyNamesToSet );
743
+
744
+ $ this ->subject ->setRules ($ rulesToSet );
745
+
746
+ self ::assertSame ($ rulesToSet , $ this ->subject ->getRules ());
747
+ }
748
+
749
+ /**
750
+ * @return DataProvider<string, array{0: list<string>, 1: list<string>}>
751
+ */
752
+ public static function provideInitialPropertyNamesAndPropertyNamesToSet (): DataProvider
753
+ {
754
+ return DataProvider::cross (self ::providePropertyNames (), self ::providePropertyNames ());
755
+ }
756
+
757
+ /**
758
+ * @test
759
+ *
760
+ * @param list<string> $initialPropertyNames
761
+ * @param list<string> $propertyNamesToSet
762
+ *
763
+ * @dataProvider provideInitialPropertyNamesAndPropertyNamesToSet
764
+ */
765
+ public function setRulesReplacesRules (array $ initialPropertyNames , array $ propertyNamesToSet ): void
766
+ {
767
+ $ rulesToSet = self ::createRulesFromPropertyNames ($ propertyNamesToSet );
768
+ $ this ->setRulesFromPropertyNames ($ initialPropertyNames );
769
+
770
+ $ this ->subject ->setRules ($ rulesToSet );
771
+
772
+ self ::assertSame ($ rulesToSet , $ this ->subject ->getRules ());
773
+ }
774
+
775
+ /**
776
+ * @test
777
+ */
778
+ public function setRulesWithRuleWithoutPositionSetsValidLineNumber (): void
779
+ {
780
+ $ ruleToSet = new Rule ('color ' );
781
+
782
+ $ this ->subject ->setRules ([$ ruleToSet ]);
783
+
784
+ self ::assertIsInt ($ ruleToSet ->getLineNumber (), 'line number not set ' );
785
+ self ::assertGreaterThanOrEqual (1 , $ ruleToSet ->getLineNumber (), 'line number not valid ' );
786
+ }
787
+
788
+ /**
789
+ * @test
790
+ */
791
+ public function setRulesWithRuleWithoutPositionSetsValidColumnNumber (): void
792
+ {
793
+ $ ruleToSet = new Rule ('color ' );
794
+
795
+ $ this ->subject ->setRules ([$ ruleToSet ]);
796
+
797
+ self ::assertIsInt ($ ruleToSet ->getColumnNumber (), 'column number not set ' );
798
+ self ::assertGreaterThanOrEqual (0 , $ ruleToSet ->getColumnNumber (), 'column number not valid ' );
799
+ }
800
+
801
+ /**
802
+ * @test
803
+ */
804
+ public function setRulesWithRuleWithOnlyLineNumberSetsColumnNumber (): void
805
+ {
806
+ $ ruleToSet = new Rule ('color ' );
807
+ $ ruleToSet ->setPosition (42 );
808
+
809
+ $ this ->subject ->setRules ([$ ruleToSet ]);
810
+
811
+ self ::assertIsInt ($ ruleToSet ->getColumnNumber (), 'column number not set ' );
812
+ self ::assertGreaterThanOrEqual (0 , $ ruleToSet ->getColumnNumber (), 'column number not valid ' );
813
+ }
814
+
815
+ /**
816
+ * @test
817
+ */
818
+ public function setRulesWithRuleWithOnlyLineNumberPreservesLineNumber (): void
819
+ {
820
+ $ ruleToSet = new Rule ('color ' );
821
+ $ ruleToSet ->setPosition (42 );
822
+
823
+ $ this ->subject ->setRules ([$ ruleToSet ]);
824
+
825
+ self ::assertSame (42 , $ ruleToSet ->getLineNumber (), 'line number not preserved ' );
826
+ }
827
+
828
+ /**
829
+ * @test
830
+ */
831
+ public function setRulesWithRuleWithOnlyColumnNumberSetsLineNumber (): void
832
+ {
833
+ $ ruleToSet = new Rule ('color ' );
834
+ $ ruleToSet ->setPosition (null , 42 );
835
+
836
+ $ this ->subject ->setRules ([$ ruleToSet ]);
837
+
838
+ self ::assertIsInt ($ ruleToSet ->getLineNumber (), 'line number not set ' );
839
+ self ::assertGreaterThanOrEqual (1 , $ ruleToSet ->getLineNumber (), 'line number not valid ' );
840
+ }
841
+
842
+ /**
843
+ * @test
844
+ */
845
+ public function setRulesWithRuleWithOnlyColumnNumberPreservesColumnNumber (): void
846
+ {
847
+ $ ruleToSet = new Rule ('color ' );
848
+ $ ruleToSet ->setPosition (null , 42 );
849
+
850
+ $ this ->subject ->setRules ([$ ruleToSet ]);
851
+
852
+ self ::assertSame (42 , $ ruleToSet ->getColumnNumber (), 'column number not preserved ' );
853
+ }
854
+
855
+ /**
856
+ * @test
857
+ */
858
+ public function setRulesWithRuleWithCompletePositionPreservesPosition (): void
859
+ {
860
+ $ ruleToSet = new Rule ('color ' );
861
+ $ ruleToSet ->setPosition (42 , 64 );
862
+
863
+ $ this ->subject ->setRules ([$ ruleToSet ]);
864
+
865
+ self ::assertSame (42 , $ ruleToSet ->getLineNumber (), 'line number not preserved ' );
866
+ self ::assertSame (64 , $ ruleToSet ->getColumnNumber (), 'column number not preserved ' );
867
+ }
868
+
733
869
/**
734
870
* @param list<string> $propertyNames
735
871
*/
736
872
private function setRulesFromPropertyNames (array $ propertyNames ): void
737
873
{
738
- $ this ->subject ->setRules (\array_map (
739
- static function (string $ propertyName ): Rule {
874
+ $ this ->subject ->setRules (self ::createRulesFromPropertyNames ($ propertyNames ));
875
+ }
876
+
877
+ /**
878
+ * @param list<string> $propertyNames
879
+ *
880
+ * @return list<Rule>
881
+ */
882
+ private static function createRulesFromPropertyNames (array $ propertyNames ): array
883
+ {
884
+ return \array_map (
885
+ function (string $ propertyName ): Rule {
740
886
return new Rule ($ propertyName );
741
887
},
742
888
$ propertyNames
743
- )) ;
889
+ );
744
890
}
745
891
}
0 commit comments