44
55namespace Linio \DynamicFormBundle \Tests \FormlyMapper \FormlyField ;
66
7+ use Linio \DynamicFormBundle \Exception \InvalidConfigurationException ;
8+ use Linio \DynamicFormBundle \Exception \NumberFormatException ;
79use Linio \DynamicFormBundle \FormlyMapper \FormlyField \BirthdayField ;
810use PHPUnit \Framework \TestCase ;
911
@@ -85,33 +87,24 @@ public function testIsAddingSpecificYears(array $fieldConfiguration, array $expe
8587 /**
8688 * @dataProvider basicDataProvider
8789 */
88- public function testWithNotNumberSpecificYears (array $ fieldConfiguration , array $ expected ): void
90+ public function testIsThrowingExceptionWhenYearsArrayHasNonNumericalValues (array $ fieldConfiguration , array $ expected ): void
8991 {
90- $ goodYears = [2000 , 2001 , 2002 , 2003 , 2004 , 2005 ];
91- $ badYears = ['2000 ' , 2001 , '2002 ' , 2003 , 2004 , 2005 ];
92+ $ this ->expectException (NumberFormatException::class);
9293
94+ $ badYears = ['2000 ' , 2001 , '20O2 ' , 2003 , 2004 , 2005 ];
9395 $ fieldConfiguration ['options ' ]['years ' ] = $ badYears ;
9496
95- $ expected ['templateOptions ' ]['years ' ] = $ goodYears ;
96-
9797 $ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
98- $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
99-
100- $ this ->assertEquals ($ expected , $ actual );
98+ $ this ->formlyField ->getFormlyFieldConfiguration ();
10199 }
102100
103101 /**
104102 * @dataProvider basicDataProvider
105103 */
106- public function testIsAddingYearsRangeInOrderByDefault (array $ fieldConfiguration , array $ expected ): void
104+ public function testItDoesNotAllowNonNumericalValuesForAllowedAges (array $ fieldConfiguration , array $ expected ): void
107105 {
108- $ minAgeAllowed = 18 ;
109- $ maxAgeAllowed = 120 ;
110-
111- $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = $ minAgeAllowed ;
112- $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = $ maxAgeAllowed ;
113-
114- $ expected ['templateOptions ' ]['years ' ] = range (date ('Y ' ) - $ minAgeAllowed , date ('Y ' ) - $ maxAgeAllowed );
106+ $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = '18a ' ;
107+ $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = 120 ;
115108
116109 $ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
117110 $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
@@ -122,10 +115,15 @@ public function testIsAddingYearsRangeInOrderByDefault(array $fieldConfiguration
122115 /**
123116 * @dataProvider basicDataProvider
124117 */
125- public function testWithBadAgeRangeForWord (array $ fieldConfiguration , array $ expected ): void
118+ public function testIsAddingYearsRangeInDefaultOrder (array $ fieldConfiguration , array $ expected ): void
126119 {
127- $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = '18a ' ;
128- $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = 120 ;
120+ $ minAgeAllowed = 18 ;
121+ $ maxAgeAllowed = 120 ;
122+
123+ $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = $ minAgeAllowed ;
124+ $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = $ maxAgeAllowed ;
125+
126+ $ expected ['templateOptions ' ]['years ' ] = range (date ('Y ' ) - $ minAgeAllowed , date ('Y ' ) - $ maxAgeAllowed );
129127
130128 $ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
131129 $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
@@ -136,7 +134,7 @@ public function testWithBadAgeRangeForWord(array $fieldConfiguration, array $exp
136134 /**
137135 * @dataProvider basicDataProvider
138136 */
139- public function testWithBadAgeRangeForNegativeNumber (array $ fieldConfiguration , array $ expected ): void
137+ public function testItDoesNotAllowNegativeValuesForAllowedAges (array $ fieldConfiguration , array $ expected ): void
140138 {
141139 $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = -2 ;
142140 $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = 120 ;
@@ -169,20 +167,15 @@ public function testWithRangeZero(array $fieldConfiguration, array $expected): v
169167 /**
170168 * @dataProvider basicDataProvider
171169 */
172- public function testWithMinAgeAllowedBiggerThanMaxAgeAllowed (array $ fieldConfiguration , array $ expected ): void
170+ public function testIsThrowExceptionWhenMinAgeAllowedValueIsLargerThanMaxAgeAllowed (array $ fieldConfiguration , array $ expected ): void
173171 {
174- $ minAgeAllowed = 18 ;
175- $ maxAgeAllowed = 120 ;
172+ $ this ->expectException (InvalidConfigurationException::class);
176173
177- $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = $ maxAgeAllowed ;
178- $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = $ minAgeAllowed ;
179-
180- $ expected ['templateOptions ' ]['years ' ] = range (date ('Y ' ) - $ minAgeAllowed , date ('Y ' ) - $ maxAgeAllowed );
174+ $ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = 120 ;
175+ $ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = 18 ;
181176
182177 $ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
183- $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
184-
185- $ this ->assertEquals ($ expected , $ actual );
178+ $ this ->formlyField ->getFormlyFieldConfiguration ();
186179 }
187180
188181 /**
0 commit comments