@@ -77,6 +77,13 @@ public function getGroup($object)
77
77
return $ this ->obj1 === $ object || $ this ->obj2 === $ object ? 'Group 1 ' : 'Group 2 ' ;
78
78
}
79
79
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
+
80
87
protected function setUp ()
81
88
{
82
89
$ this ->obj1 = (object ) array ('label ' => 'A ' , 'index ' => 'w ' , 'value ' => 'a ' , 'preferred ' => false , 'group ' => 'Group 1 ' , 'attr ' => array ());
@@ -581,6 +588,19 @@ public function testCreateViewFlatGroupByAsCallable()
581
588
$ this ->assertGroupedView ($ view );
582
589
}
583
590
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
+
584
604
public function testCreateViewFlatGroupByAsClosure ()
585
605
{
586
606
$ obj1 = $ this ->obj1 ;
@@ -897,3 +917,18 @@ private function assertGroupedView($view)
897
917
), $ view );
898
918
}
899
919
}
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