File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
src/Symfony/Component/DomCrawler Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -124,13 +124,15 @@ public function has($name)
124
124
public function set ($ name , $ value )
125
125
{
126
126
$ target = &$ this ->get ($ name );
127
- if (!is_array ($ value ) || $ target instanceof Field \ChoiceFormField) {
127
+ if (( !is_array ($ value) && $ target instanceof Field \FormField ) || $ target instanceof Field \ChoiceFormField) {
128
128
$ target ->setValue ($ value );
129
- } else {
129
+ } elseif ( is_array ( $ value )) {
130
130
$ fields = self ::create ($ name , $ value );
131
131
foreach ($ fields ->all () as $ k => $ v ) {
132
132
$ this ->set ($ k , $ v );
133
133
}
134
+ } else {
135
+ throw new \InvalidArgumentException (sprintf ('Cannot set value on a compound field "%s". ' , $ name ));
134
136
}
135
137
}
136
138
Original file line number Diff line number Diff line change @@ -787,6 +787,31 @@ public function testFormRegistrySetValues()
787
787
));
788
788
}
789
789
790
+ /**
791
+ * @expectedException \InvalidArgumentException
792
+ * @expectedExceptionMessage Cannot set value on a compound field "foo[bar]".
793
+ */
794
+ public function testFormRegistrySetValueOnCompoundField ()
795
+ {
796
+ $ registry = new FormFieldRegistry ();
797
+ $ registry ->add ($ this ->getFormFieldMock ('foo[bar][baz] ' ));
798
+
799
+ $ registry ->set ('foo[bar] ' , 'fbb ' );
800
+ }
801
+
802
+ /**
803
+ * @expectedException InvalidArgumentException
804
+ * @expectedExceptionMessage Unreachable field "0"
805
+ */
806
+ public function testFormRegistrySetArrayOnNotCompoundField ()
807
+ {
808
+
809
+ $ registry = new FormFieldRegistry ();
810
+ $ registry ->add ($ this ->getFormFieldMock ('bar ' ));
811
+
812
+ $ registry ->set ('bar ' , array ('baz ' ));
813
+ }
814
+
790
815
public function testDifferentFieldTypesWithSameName ()
791
816
{
792
817
$ dom = new \DOMDocument ();
You can’t perform that action at this time.
0 commit comments