@@ -302,13 +302,52 @@ public function testCreateThrowsUnderstandableException()
302
302
$ this ->factory ->create (new \stdClass ());
303
303
}
304
304
305
+ public function testCreateUsesBlockPrefixIfTypeGivenAsString ()
306
+ {
307
+ $ options = array ('a ' => '1 ' , 'b ' => '2 ' );
308
+ $ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
309
+
310
+ // the interface does not have the method, so use the real class
311
+ $ resolvedType = $ this ->getMockBuilder ('Symfony\Component\Form\ResolvedFormType ' )
312
+ ->disableOriginalConstructor ()
313
+ ->getMock ();
314
+
315
+ $ resolvedType ->expects ($ this ->any ())
316
+ ->method ('getBlockPrefix ' )
317
+ ->willReturn ('TYPE_PREFIX ' );
318
+
319
+ $ this ->registry ->expects ($ this ->any ())
320
+ ->method ('getType ' )
321
+ ->with ('TYPE ' )
322
+ ->will ($ this ->returnValue ($ resolvedType ));
323
+
324
+ $ resolvedType ->expects ($ this ->once ())
325
+ ->method ('createBuilder ' )
326
+ ->with ($ this ->factory , 'TYPE_PREFIX ' , $ options )
327
+ ->will ($ this ->returnValue ($ this ->builder ));
328
+
329
+ $ this ->builder ->expects ($ this ->any ())
330
+ ->method ('getOptions ' )
331
+ ->will ($ this ->returnValue ($ resolvedOptions ));
332
+
333
+ $ resolvedType ->expects ($ this ->once ())
334
+ ->method ('buildForm ' )
335
+ ->with ($ this ->builder , $ resolvedOptions );
336
+
337
+ $ this ->builder ->expects ($ this ->once ())
338
+ ->method ('getForm ' )
339
+ ->will ($ this ->returnValue ('FORM ' ));
340
+
341
+ $ this ->assertSame ('FORM ' , $ this ->factory ->create ('TYPE ' , null , $ options ));
342
+ }
343
+
305
344
public function testCreateUsesTypeNameIfTypeGivenAsString ()
306
345
{
307
346
$ options = array ('a ' => '1 ' , 'b ' => '2 ' );
308
347
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
309
348
$ resolvedType = $ this ->getMockResolvedType ();
310
349
311
- $ this ->registry ->expects ($ this ->once ())
350
+ $ this ->registry ->expects ($ this ->any ())
312
351
->method ('getType ' )
313
352
->with ('TYPE ' )
314
353
->will ($ this ->returnValue ($ resolvedType ));
@@ -339,7 +378,7 @@ public function testCreateStripsNamespaceOffTypeName()
339
378
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
340
379
$ resolvedType = $ this ->getMockResolvedType ();
341
380
342
- $ this ->registry ->expects ($ this ->once ())
381
+ $ this ->registry ->expects ($ this ->any ())
343
382
->method ('getType ' )
344
383
->with ('Vendor\Name\Space\UserForm ' )
345
384
->will ($ this ->returnValue ($ resolvedType ));
@@ -370,7 +409,7 @@ public function testLegacyCreateStripsNamespaceOffTypeNameAccessByFQCN()
370
409
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
371
410
$ resolvedType = $ this ->getMockResolvedType ();
372
411
373
- $ this ->registry ->expects ($ this ->once ())
412
+ $ this ->registry ->expects ($ this ->any ())
374
413
->method ('getType ' )
375
414
->with ('userform ' )
376
415
->will ($ this ->returnValue ($ resolvedType ));
@@ -401,7 +440,7 @@ public function testCreateStripsTypeSuffixOffTypeName()
401
440
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
402
441
$ resolvedType = $ this ->getMockResolvedType ();
403
442
404
- $ this ->registry ->expects ($ this ->once ())
443
+ $ this ->registry ->expects ($ this ->any ())
405
444
->method ('getType ' )
406
445
->with ('Vendor\Name\Space\UserType ' )
407
446
->will ($ this ->returnValue ($ resolvedType ));
@@ -432,7 +471,7 @@ public function testCreateDoesNotStripTypeSuffixIfResultEmpty()
432
471
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
433
472
$ resolvedType = $ this ->getMockResolvedType ();
434
473
435
- $ this ->registry ->expects ($ this ->once ())
474
+ $ this ->registry ->expects ($ this ->any ())
436
475
->method ('getType ' )
437
476
->with ('Vendor\Name\Space\Type ' )
438
477
->will ($ this ->returnValue ($ resolvedType ));
@@ -463,7 +502,7 @@ public function testCreateConvertsTypeToUnderscoreSyntax()
463
502
$ resolvedOptions = array ('a ' => '2 ' , 'b ' => '3 ' );
464
503
$ resolvedType = $ this ->getMockResolvedType ();
465
504
466
- $ this ->registry ->expects ($ this ->once ())
505
+ $ this ->registry ->expects ($ this ->any ())
467
506
->method ('getType ' )
468
507
->with ('Vendor\Name\Space\MyProfileHTMLType ' )
469
508
->will ($ this ->returnValue ($ resolvedType ));
0 commit comments