4
4
5
5
namespace Linio \DynamicFormBundle \Tests \FormlyMapper \FormlyField ;
6
6
7
+ use Linio \DynamicFormBundle \Exception \InvalidConfigurationException ;
8
+ use Linio \DynamicFormBundle \Exception \NumberFormatException ;
7
9
use Linio \DynamicFormBundle \FormlyMapper \FormlyField \BirthdayField ;
8
10
use PHPUnit \Framework \TestCase ;
9
11
@@ -85,33 +87,24 @@ public function testIsAddingSpecificYears(array $fieldConfiguration, array $expe
85
87
/**
86
88
* @dataProvider basicDataProvider
87
89
*/
88
- public function testWithNotNumberSpecificYears (array $ fieldConfiguration , array $ expected ): void
90
+ public function testIsThrowingExceptionWhenYearsArrayHasNonNumericalValues (array $ fieldConfiguration , array $ expected ): void
89
91
{
90
- $ goodYears = [2000 , 2001 , 2002 , 2003 , 2004 , 2005 ];
91
- $ badYears = ['2000 ' , 2001 , '2002 ' , 2003 , 2004 , 2005 ];
92
+ $ this ->expectException (NumberFormatException::class);
92
93
94
+ $ badYears = ['2000 ' , 2001 , '20O2 ' , 2003 , 2004 , 2005 ];
93
95
$ fieldConfiguration ['options ' ]['years ' ] = $ badYears ;
94
96
95
- $ expected ['templateOptions ' ]['years ' ] = $ goodYears ;
96
-
97
97
$ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
98
- $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
99
-
100
- $ this ->assertEquals ($ expected , $ actual );
98
+ $ this ->formlyField ->getFormlyFieldConfiguration ();
101
99
}
102
100
103
101
/**
104
102
* @dataProvider basicDataProvider
105
103
*/
106
- public function testIsAddingYearsRangeInOrderByDefault (array $ fieldConfiguration , array $ expected ): void
104
+ public function testItDoesNotAllowNonNumericalValuesForAllowedAges (array $ fieldConfiguration , array $ expected ): void
107
105
{
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 ;
115
108
116
109
$ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
117
110
$ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
@@ -122,10 +115,15 @@ public function testIsAddingYearsRangeInOrderByDefault(array $fieldConfiguration
122
115
/**
123
116
* @dataProvider basicDataProvider
124
117
*/
125
- public function testWithBadAgeRangeForWord (array $ fieldConfiguration , array $ expected ): void
118
+ public function testIsAddingYearsRangeInDefaultOrder (array $ fieldConfiguration , array $ expected ): void
126
119
{
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 );
129
127
130
128
$ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
131
129
$ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
@@ -136,7 +134,7 @@ public function testWithBadAgeRangeForWord(array $fieldConfiguration, array $exp
136
134
/**
137
135
* @dataProvider basicDataProvider
138
136
*/
139
- public function testWithBadAgeRangeForNegativeNumber (array $ fieldConfiguration , array $ expected ): void
137
+ public function testItDoesNotAllowNegativeValuesForAllowedAges (array $ fieldConfiguration , array $ expected ): void
140
138
{
141
139
$ fieldConfiguration ['options ' ]['minAgeAllowed ' ] = -2 ;
142
140
$ fieldConfiguration ['options ' ]['maxAgeAllowed ' ] = 120 ;
@@ -169,20 +167,15 @@ public function testWithRangeZero(array $fieldConfiguration, array $expected): v
169
167
/**
170
168
* @dataProvider basicDataProvider
171
169
*/
172
- public function testWithMinAgeAllowedBiggerThanMaxAgeAllowed (array $ fieldConfiguration , array $ expected ): void
170
+ public function testIsThrowExceptionWhenMinAgeAllowedValueIsLargerThanMaxAgeAllowed (array $ fieldConfiguration , array $ expected ): void
173
171
{
174
- $ minAgeAllowed = 18 ;
175
- $ maxAgeAllowed = 120 ;
172
+ $ this ->expectException (InvalidConfigurationException::class);
176
173
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 ;
181
176
182
177
$ this ->formlyField ->setFieldConfiguration ($ fieldConfiguration );
183
- $ actual = $ this ->formlyField ->getFormlyFieldConfiguration ();
184
-
185
- $ this ->assertEquals ($ expected , $ actual );
178
+ $ this ->formlyField ->getFormlyFieldConfiguration ();
186
179
}
187
180
188
181
/**
0 commit comments