File tree Expand file tree Collapse file tree 2 files changed +9
-19
lines changed Expand file tree Collapse file tree 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)
356356 if (!FormUtil::isEmpty ($ viewData )) {
357357 $ dataClass = $ this ->config ->getDataClass ();
358358
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-
373359 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+
374364 throw new LogicException (
375365 'The form \'s view data is expected to be an instance of class ' .
376366 $ 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
840840 $ this ->assertEquals (new PropertyPath ('[name] ' ), $ form ->getPropertyPath ());
841841 }
842842
843- /**
844- * @expectedException \Symfony\Component\Form\Exception\LogicException
845- */
846- public function testViewDataMustNotBeObjectIfDataClassIsNull ()
843+ public function testViewDataMayBeObjectIfDataClassIsNull ()
847844 {
845+ $ object = new \stdClass ();
848846 $ config = new FormConfigBuilder ('name ' , null , $ this ->dispatcher );
849847 $ config ->addViewTransformer (new FixedDataTransformer (array (
850848 '' => '' ,
851- 'foo ' => new \ stdClass () ,
849+ 'foo ' => $ object ,
852850 )));
853851 $ form = new Form ($ config );
854852
855853 $ form ->setData ('foo ' );
854+
855+ $ this ->assertSame ($ object , $ form ->getViewData ());
856856 }
857857
858858 public function testViewDataMayBeArrayAccessIfDataClassIsNull ()
You can’t perform that action at this time.
0 commit comments