@@ -33,15 +33,16 @@ class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase
3333 public function testCreateFromValidationConstraint (
3434 Constraint $ constraint ,
3535 FormInterface $ form ,
36- ?ConstraintInterface $ expected
36+ ?ConstraintInterface $ expected ,
37+ string $ testName
3738 ) {
3839 $ return = null ;
3940 try {
4041 $ return = ConstraintFactory::createFromValidationConstraint ($ constraint , $ form );
4142 } catch (\RuntimeException $ exception ) {
4243
4344 }
44- self ::assertEquals ($ expected , $ return );
45+ self ::assertEquals ($ expected , $ return, $ testName );
4546 }
4647
4748 /**
@@ -71,6 +72,7 @@ public function getFactoryTestData()
7172 ),
7273 $ form ->get ('id ' ),
7374 new Pattern ('/pattern/ ' , 'This doesn \'t look right ' ),
75+ 'Regex to Pattern ' ,
7476 ],
7577 [
7678 new Length (
@@ -82,6 +84,7 @@ public function getFactoryTestData()
8284 ),
8385 $ form ->get ('id ' ),
8486 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Length (1 , 20 , 'This doesn \'t look right ' ),
87+ 'Length to Length ' ,
8588 ],
8689 [
8790 new Length (
@@ -92,6 +95,7 @@ public function getFactoryTestData()
9295 ),
9396 $ form ->get ('id ' ),
9497 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \MinLength (1 , 'This doesn \'t look right ' ),
98+ 'Length to MinLength ' ,
9599 ],
96100 [
97101 new Length (
@@ -102,6 +106,7 @@ public function getFactoryTestData()
102106 ),
103107 $ form ->get ('id ' ),
104108 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \MaxLength (20 , 'This doesn \'t look right ' ),
109+ 'Length to MaxLength ' ,
105110 ],
106111 [
107112 new Email (
@@ -111,6 +116,7 @@ public function getFactoryTestData()
111116 ),
112117 $ form ->get ('id ' ),
113118 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Email ('This doesn \'t look right ' ),
119+ 'Email to Email ' ,
114120 ],
115121
116122 // Max 'n' Min (integer)
@@ -119,21 +125,25 @@ public function getFactoryTestData()
119125 new GreaterThanOrEqual (['value ' => 10 , 'message ' => 'Ouch ' ]),
120126 $ form ->get ('id ' ),
121127 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min (10 , 'Ouch ' ),
128+ 'GreaterThanOrEqual to Min (integer) ' ,
122129 ],
123130 [
124131 new GreaterThan (['value ' => 10 , 'message ' => 'Ouch ' ]),
125132 $ form ->get ('id ' ),
126133 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min (11 , 'Ouch ' ),
134+ 'GreaterThan to Min (integer) ' ,
127135 ],
128136 [
129137 new LessThanOrEqual (['value ' => 10 , 'message ' => 'Ouch ' ]),
130138 $ form ->get ('id ' ),
131139 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max (10 , 'Ouch ' ),
140+ 'LessThanOrEqual to Max (integer) ' ,
132141 ],
133142 [
134143 new LessThan (['value ' => 10 , 'message ' => 'Ouch ' ]),
135144 $ form ->get ('id ' ),
136145 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max (9 , 'Ouch ' ),
146+ 'LessThan to Max (integer) ' ,
137147 ],
138148
139149 // Max 'n' Min (float)
@@ -142,21 +152,25 @@ public function getFactoryTestData()
142152 new GreaterThanOrEqual (['value ' => 10.0 , 'message ' => 'Ouch ' ]),
143153 $ form ->get ('id ' ),
144154 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min (10 , 'Ouch ' ),
155+ 'GreaterThanOrEqual to Min (float) ' ,
145156 ],
146157 [
147158 new GreaterThan (['value ' => 10.0 , 'message ' => 'Ouch ' ]),
148159 $ form ->get ('id ' ),
149160 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min (10.0000001 , 'Ouch ' ),
161+ 'GreaterThan to Min (float) ' ,
150162 ],
151163 [
152164 new LessThanOrEqual (['value ' => 10.0 , 'message ' => 'Ouch ' ]),
153165 $ form ->get ('id ' ),
154166 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max (10 , 'Ouch ' ),
167+ 'LessThanOrEqual to Max (float) ' ,
155168 ],
156169 [
157170 new LessThan (['value ' => 10.0 , 'message ' => 'Ouch ' ]),
158171 $ form ->get ('id ' ),
159172 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max (9.9999999 , 'Ouch ' ),
173+ 'LessThanOrEqual to Max (float) ' ,
160174 ],
161175
162176 // Max 'n' Min (DateTime) (The id field isn't a DateType so we shouldn't get a result back!)
@@ -165,21 +179,25 @@ public function getFactoryTestData()
165179 new GreaterThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
166180 $ form ->get ('id ' ),
167181 null ,
182+ 'GreaterThanOrEqual to Null (date (non-date field)) ' ,
168183 ],
169184 [
170185 new GreaterThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
171186 $ form ->get ('id ' ),
172187 null ,
188+ 'GreaterThan to Null (date (non-date field)) ' ,
173189 ],
174190 [
175191 new LessThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
176192 $ form ->get ('id ' ),
177193 null ,
194+ 'LessThanOrEqual to Null (date (non-date field)) ' ,
178195 ],
179196 [
180197 new LessThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
181198 $ form ->get ('id ' ),
182199 null ,
200+ 'LessThan to Null (date (non-date field)) ' ,
183201 ],
184202
185203 // Max 'n' Min (DateTime) (The date field is a DateType so we should get a result back!)
@@ -188,21 +206,25 @@ public function getFactoryTestData()
188206 new GreaterThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
189207 $ form ->get ('date ' ),
190208 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min ('2018-01-19 00:00:00 ' , 'Ouch ' ),
209+ 'GreaterThanOrEqual to Min (date (date field)) ' ,
191210 ],
192211 [
193212 new GreaterThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
194213 $ form ->get ('date ' ),
195214 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min ('2018-01-19 00:00:01 ' , 'Ouch ' ),
215+ 'GreaterThan to Min (date (date field)) ' ,
196216 ],
197217 [
198218 new LessThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
199219 $ form ->get ('date ' ),
200220 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max ('2018-01-19 00:00:00 ' , 'Ouch ' ),
221+ 'LessThanOrEqual to Max (date (date field)) ' ,
201222 ],
202223 [
203224 new LessThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
204225 $ form ->get ('date ' ),
205226 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max ('2018-01-18 23:59:59 ' , 'Ouch ' ),
227+ 'LessThan to Max (date (date field)) ' ,
206228 ],
207229
208230 // Max 'n' Min (DateTime) (The dob field is a BirthdayType so we shoul get a result back!)
@@ -211,21 +233,52 @@ public function getFactoryTestData()
211233 new GreaterThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
212234 $ form ->get ('dob ' ),
213235 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min ('2018-01-19 00:00:00 ' , 'Ouch ' ),
236+ 'GreaterThanOrEqual to Min (date (birthday field)) ' ,
214237 ],
215238 [
216239 new GreaterThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
217240 $ form ->get ('dob ' ),
218241 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Min ('2018-01-19 00:00:01 ' , 'Ouch ' ),
242+ 'GreaterThan to Min (date (birthday field)) ' ,
219243 ],
220244 [
221245 new LessThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
222246 $ form ->get ('dob ' ),
223247 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max ('2018-01-19 00:00:00 ' , 'Ouch ' ),
248+ 'LessThanOrEqual to Min (date (birthday field)) ' ,
224249 ],
225250 [
226251 new LessThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
227252 $ form ->get ('dob ' ),
228253 new \C0ntax \ParsleyBundle \Directive \Field \Constraint \Max ('2018-01-18 23:59:59 ' , 'Ouch ' ),
254+ 'LessThan to Min (date (birthday field)) ' ,
255+ ],
256+
257+ // Max 'n' Min (DateTime) (The dateNotHtml field is a DateType but not HTML5 so we should get null back)
258+
259+ [
260+ new GreaterThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
261+ $ form ->get ('dateNotHtml5 ' ),
262+ null ,
263+ 'GreaterThanOrEqual to Null (date (non-html5-date field)) ' ,
264+ ],
265+ [
266+ new GreaterThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
267+ $ form ->get ('dateNotHtml5 ' ),
268+ null ,
269+ 'GreaterThan to Null (date (non-html5-date field)) ' ,
270+ ],
271+ [
272+ new LessThanOrEqual (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
273+ $ form ->get ('dateNotHtml5 ' ),
274+ null ,
275+ 'LessThanOrEqual to Null (date (non-html5-date field)) ' ,
276+ ],
277+ [
278+ new LessThan (['value ' => '2018-01-19 ' , 'message ' => 'Ouch ' ]),
279+ $ form ->get ('dateNotHtml5 ' ),
280+ null ,
281+ 'LessThan to Null (date (non-html5-date field)) ' ,
229282 ],
230283 ];
231284 }
0 commit comments