File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
src/Symfony/Component/Validator Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,9 @@ public function __construct($options = null)
129
129
unset($ options ['value ' ]);
130
130
}
131
131
132
+ if (is_array ($ options )) {
133
+ reset ($ options );
134
+ }
132
135
if (is_array ($ options ) && count ($ options ) > 0 && is_string (key ($ options ))) {
133
136
foreach ($ options as $ option => $ value ) {
134
137
if (array_key_exists ($ option , $ knownOptions )) {
Original file line number Diff line number Diff line change @@ -206,4 +206,35 @@ public function testGetErrorNameForUnknownCode()
206
206
{
207
207
Constraint::getErrorName (1 );
208
208
}
209
+
210
+ public function testOptionsAsDefaultOption ()
211
+ {
212
+ $ constraint = new ConstraintA ($ options = array ('value1 ' ));
213
+
214
+ $ this ->assertEquals ($ options , $ constraint ->property2 );
215
+
216
+ $ constraint = new ConstraintA ($ options = array ('value1 ' , 'property1 ' => 'value2 ' ));
217
+
218
+ $ this ->assertEquals ($ options , $ constraint ->property2 );
219
+ }
220
+
221
+ /**
222
+ * @expectedException \Symfony\Component\Validator\Exception\InvalidOptionsException
223
+ * @expectedExceptionMessage The options "0", "5" do not exist
224
+ */
225
+ public function testInvalidOptions ()
226
+ {
227
+ new ConstraintA (array ('property2 ' => 'foo ' , 'bar ' , 5 => 'baz ' ));
228
+ }
229
+
230
+ public function testOptionsWithInvalidInternalPointer ()
231
+ {
232
+ $ options = array ('property1 ' => 'foo ' );
233
+ next ($ options );
234
+ next ($ options );
235
+
236
+ $ constraint = new ConstraintA ($ options );
237
+
238
+ $ this ->assertEquals ('foo ' , $ constraint ->property1 );
239
+ }
209
240
}
You can’t perform that action at this time.
0 commit comments