File tree 2 files changed +9
-19
lines changed
Filter options
src/Symfony/Component/Form
2 files changed +9
-19
lines changed
Original file line number Diff line number Diff line change @@ -356,21 +356,11 @@ public function setData($modelData)
356
356
if (!FormUtil::isEmpty ($ viewData )) {
357
357
$ dataClass = $ this ->config ->getDataClass ();
358
358
359
- $ actualType = is_object ($ viewData ) ? 'an instance of class ' .get_class ($ viewData ) : 'a(n) ' .gettype ($ viewData );
360
-
361
- if (null === $ dataClass && is_object ($ viewData ) && !$ viewData instanceof \ArrayAccess) {
362
- $ expectedType = 'scalar, array or an instance of \ArrayAccess ' ;
363
-
364
- throw new LogicException (
365
- 'The form \'s view data is expected to be of type ' .$ expectedType .', ' .
366
- 'but is ' .$ actualType .'. You ' .
367
- 'can avoid this error by setting the "data_class" option to ' .
368
- '" ' .get_class ($ viewData ).'" or by adding a view transformer ' .
369
- 'that transforms ' .$ actualType .' to ' .$ expectedType .'. '
370
- );
371
- }
372
-
373
359
if (null !== $ dataClass && !$ viewData instanceof $ dataClass ) {
360
+ $ actualType = is_object ($ viewData )
361
+ ? 'an instance of class ' .get_class ($ viewData )
362
+ : 'a(n) ' .gettype ($ viewData );
363
+
374
364
throw new LogicException (
375
365
'The form \'s view data is expected to be an instance of class ' .
376
366
$ dataClass .', but is ' .$ actualType .'. You can avoid this error ' .
Original file line number Diff line number Diff line change @@ -840,19 +840,19 @@ public function testGetPropertyPathDefaultsToIndexedNameIfDataClassOfFirstParent
840
840
$ this ->assertEquals (new PropertyPath ('[name] ' ), $ form ->getPropertyPath ());
841
841
}
842
842
843
- /**
844
- * @expectedException \Symfony\Component\Form\Exception\LogicException
845
- */
846
- public function testViewDataMustNotBeObjectIfDataClassIsNull ()
843
+ public function testViewDataMayBeObjectIfDataClassIsNull ()
847
844
{
845
+ $ object = new \stdClass ();
848
846
$ config = new FormConfigBuilder ('name ' , null , $ this ->dispatcher );
849
847
$ config ->addViewTransformer (new FixedDataTransformer (array (
850
848
'' => '' ,
851
- 'foo ' => new \ stdClass () ,
849
+ 'foo ' => $ object ,
852
850
)));
853
851
$ form = new Form ($ config );
854
852
855
853
$ form ->setData ('foo ' );
854
+
855
+ $ this ->assertSame ($ object , $ form ->getViewData ());
856
856
}
857
857
858
858
public function testViewDataMayBeArrayAccessIfDataClassIsNull ()
You can’t perform that action at this time.
0 commit comments