@@ -1140,6 +1140,69 @@ public function testLoaderCaching()
1140
1140
$ this ->assertSame ($ choiceLoader1 , $ choiceLoader3 );
1141
1141
}
1142
1142
1143
+ public function testLoaderCachingWithParameters ()
1144
+ {
1145
+ $ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
1146
+ $ entity2 = new SingleIntIdEntity (2 , 'Bar ' );
1147
+ $ entity3 = new SingleIntIdEntity (3 , 'Baz ' );
1148
+
1149
+ $ this ->persist (array ($ entity1 , $ entity2 , $ entity3 ));
1150
+
1151
+ $ repo = $ this ->em ->getRepository (self ::SINGLE_IDENT_CLASS );
1152
+
1153
+ $ entityType = new EntityType (
1154
+ $ this ->emRegistry ,
1155
+ PropertyAccess::createPropertyAccessor ()
1156
+ );
1157
+
1158
+ $ entityTypeGuesser = new DoctrineOrmTypeGuesser ($ this ->emRegistry );
1159
+
1160
+ $ factory = Forms::createFormFactoryBuilder ()
1161
+ ->addType ($ entityType )
1162
+ ->addTypeGuesser ($ entityTypeGuesser )
1163
+ ->getFormFactory ();
1164
+
1165
+ $ formBuilder = $ factory ->createNamedBuilder ('form ' , 'form ' );
1166
+
1167
+ $ formBuilder ->add ('property1 ' , 'entity ' , array (
1168
+ 'em ' => 'default ' ,
1169
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1170
+ 'query_builder ' => $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 ),
1171
+ ));
1172
+
1173
+ $ formBuilder ->add ('property2 ' , 'entity ' , array (
1174
+ 'em ' => 'default ' ,
1175
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1176
+ 'query_builder ' => function (EntityRepository $ repo ) {
1177
+ return $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 );
1178
+ },
1179
+ ));
1180
+
1181
+ $ formBuilder ->add ('property3 ' , 'entity ' , array (
1182
+ 'em ' => 'default ' ,
1183
+ 'class ' => self ::SINGLE_IDENT_CLASS ,
1184
+ 'query_builder ' => function (EntityRepository $ repo ) {
1185
+ return $ repo ->createQueryBuilder ('e ' )->where ('e.id = :id ' )->setParameter ('id ' , 1 );
1186
+ },
1187
+ ));
1188
+
1189
+ $ form = $ formBuilder ->getForm ();
1190
+
1191
+ $ form ->submit (array (
1192
+ 'property1 ' => 1 ,
1193
+ 'property2 ' => 1 ,
1194
+ 'property3 ' => 2 ,
1195
+ ));
1196
+
1197
+ $ choiceList1 = $ form ->get ('property1 ' )->getConfig ()->getOption ('choice_list ' );
1198
+ $ choiceList2 = $ form ->get ('property2 ' )->getConfig ()->getOption ('choice_list ' );
1199
+ $ choiceList3 = $ form ->get ('property3 ' )->getConfig ()->getOption ('choice_list ' );
1200
+
1201
+ $ this ->assertInstanceOf ('Symfony\Component\Form\ChoiceList\ChoiceListInterface ' , $ choiceList1 );
1202
+ $ this ->assertSame ($ choiceList1 , $ choiceList2 );
1203
+ $ this ->assertSame ($ choiceList1 , $ choiceList3 );
1204
+ }
1205
+
1143
1206
public function testCacheChoiceLists ()
1144
1207
{
1145
1208
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
0 commit comments