@@ -978,6 +978,69 @@ public function testLoaderCaching()
978
978
$ this ->assertSame ($ choiceList1 , $ choiceList3 );
979
979
}
980
980
981
+ public function testLoaderCachingWithParameters ()
982
+ {
983
+ $ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
984
+ $ entity2 = new SingleIntIdEntity (2 , 'Bar ' );
985
+ $ entity3 = new SingleIntIdEntity (3 , 'Baz ' );
986
+
987
+ $ this ->persist (array ($ entity1 , $ entity2 , $ entity3 ));
988
+
989
+ $ repo = $ this ->em ->getRepository (self ::SINGLE_IDENT_CLASS );
990
+
991
+ $ entityType = new EntityType (
992
+ $ this ->emRegistry ,
993
+ PropertyAccess::createPropertyAccessor ()
994
+ );
995
+
996
+ $ entityTypeGuesser = new DoctrineOrmTypeGuesser ($ this ->emRegistry );
997
+
998
+ $ factory = Forms::createFormFactoryBuilder ()
999
+ ->addType ($ entityType )
1000
+ ->addTypeGuesser ($ entityTypeGuesser )
1001
+ ->getFormFactory ();
1002
+
1003
+ $ formBuilder = $ factory ->createNamedBuilder ('form ' , 'form ' );
1004
+
1005
+ $ formBuilder ->add ('property1 ' , 'entity ' , array (
1006
+ 'em ' => 'default ' ,
1007
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1008
+ 'query_builder ' => $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 ),
1009
+ ));
1010
+
1011
+ $ formBuilder ->add ('property2 ' , 'entity ' , array (
1012
+ 'em ' => 'default ' ,
1013
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1014
+ 'query_builder ' => function (EntityRepository $ repo ) {
1015
+ return $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 );
1016
+ },
1017
+ ));
1018
+
1019
+ $ formBuilder ->add ('property3 ' , 'entity ' , array (
1020
+ 'em ' => 'default ' ,
1021
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1022
+ 'query_builder ' => function (EntityRepository $ repo ) {
1023
+ return $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 );
1024
+ },
1025
+ ));
1026
+
1027
+ $ form = $ formBuilder ->getForm ();
1028
+
1029
+ $ form ->submit (array (
1030
+ 'property1 ' => 1 ,
1031
+ 'property2 ' => 1 ,
1032
+ 'property3 ' => 2 ,
1033
+ ));
1034
+
1035
+ $ choiceList1 = $ form ->get ('property1 ' )->getConfig ()->getOption ('choice_list ' );
1036
+ $ choiceList2 = $ form ->get ('property2 ' )->getConfig ()->getOption ('choice_list ' );
1037
+ $ choiceList3 = $ form ->get ('property3 ' )->getConfig ()->getOption ('choice_list ' );
1038
+
1039
+ $ this ->assertInstanceOf ('Symfony\Component\Form\ChoiceList\ChoiceListInterface ' , $ choiceList1 );
1040
+ $ this ->assertSame ($ choiceList1 , $ choiceList2 );
1041
+ $ this ->assertSame ($ choiceList1 , $ choiceList3 );
1042
+ }
1043
+
981
1044
public function testCacheChoiceLists ()
982
1045
{
983
1046
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
0 commit comments