@@ -77,6 +77,13 @@ public function getGroup($object)
7777 return $ this ->obj1 === $ object || $ this ->obj2 === $ object ? 'Group 1 ' : 'Group 2 ' ;
7878 }
7979
80+ public function getGroupAsObject ($ object )
81+ {
82+ return $ this ->obj1 === $ object || $ this ->obj2 === $ object
83+ ? new DefaultChoiceListFactoryTest_Castable ('Group 1 ' )
84+ : new DefaultChoiceListFactoryTest_Castable ('Group 2 ' );
85+ }
86+
8087 protected function setUp ()
8188 {
8289 $ this ->obj1 = (object ) array ('label ' => 'A ' , 'index ' => 'w ' , 'value ' => 'a ' , 'preferred ' => false , 'group ' => 'Group 1 ' , 'attr ' => array ());
@@ -581,6 +588,19 @@ public function testCreateViewFlatGroupByAsCallable()
581588 $ this ->assertGroupedView ($ view );
582589 }
583590
591+ public function testCreateViewFlatGroupByObjectThatCanBeCastToString ()
592+ {
593+ $ view = $ this ->factory ->createView (
594+ $ this ->list ,
595+ array ($ this ->obj2 , $ this ->obj3 ),
596+ null , // label
597+ null , // index
598+ array ($ this , 'getGroupAsObject ' )
599+ );
600+
601+ $ this ->assertGroupedView ($ view );
602+ }
603+
584604 public function testCreateViewFlatGroupByAsClosure ()
585605 {
586606 $ obj1 = $ this ->obj1 ;
@@ -897,3 +917,18 @@ private function assertGroupedView($view)
897917 ), $ view );
898918 }
899919}
920+
921+ class DefaultChoiceListFactoryTest_Castable
922+ {
923+ private $ property ;
924+
925+ public function __construct ($ property )
926+ {
927+ $ this ->property = $ property ;
928+ }
929+
930+ public function __toString ()
931+ {
932+ return $ this ->property ;
933+ }
934+ }
0 commit comments