@@ -61,9 +61,8 @@ public function testValidate()
61
61
{
62
62
$ object = new \stdClass ();
63
63
$ options = ['validation_groups ' => ['group1 ' , 'group2 ' ]];
64
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
65
- ->setData ($ object )
66
- ->getForm ();
64
+ $ form = $ this ->getCompoundForm ($ object , $ options );
65
+ $ form ->submit ([]);
67
66
68
67
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
69
68
@@ -82,9 +81,8 @@ public function testValidateConstraints()
82
81
'validation_groups ' => ['group1 ' , 'group2 ' ],
83
82
'constraints ' => [$ constraint1 , $ constraint2 ],
84
83
];
85
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
86
- ->setData ($ object )
87
- ->getForm ();
84
+ $ form = $ this ->getCompoundForm ($ object , $ options );
85
+ $ form ->submit ([]);
88
86
89
87
// First default constraints
90
88
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
@@ -110,10 +108,9 @@ public function testValidateChildIfValidConstraint()
110
108
'validation_groups ' => ['group1 ' , 'group2 ' ],
111
109
'constraints ' => [new Valid ()],
112
110
];
113
- $ form = $ this ->getBuilder ( ' name ' , ' \stdClass ' , $ options)-> getForm ( );
111
+ $ form = $ this ->getCompoundForm ( $ object , $ options );
114
112
$ parent ->add ($ form );
115
-
116
- $ form ->setData ($ object );
113
+ $ parent ->submit ([]);
117
114
118
115
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
119
116
@@ -146,8 +143,8 @@ public function testDontValidateIfParentWithoutValidConstraint()
146
143
public function testMissingConstraintIndex ()
147
144
{
148
145
$ object = new \stdClass ();
149
- $ form = new FormBuilder ( ' name ' , ' \stdClass ' , $ this ->dispatcher , $ this -> factory );
150
- $ form = $ form -> setData ( $ object )-> getForm ( );
146
+ $ form = $ this ->getCompoundForm ( $ object );
147
+ $ form-> submit ([] );
151
148
152
149
$ this ->expectValidateAt (0 , 'data ' , $ object , ['Default ' ]);
153
150
@@ -170,10 +167,9 @@ public function testValidateConstraintsOptionEvenIfNoValidConstraint()
170
167
'validation_groups ' => ['group1 ' , 'group2 ' ],
171
168
'constraints ' => [$ constraint1 , $constraint2 ],
172
169
];
173
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
174
- ->setData ($ object )
175
- ->getForm ();
170
+ $ form = $ this ->getCompoundForm ($ object , $ options );
176
171
$ parent ->add ($ form );
172
+ $ parent ->submit ([]);
177
173
178
174
$ this ->expectValidateValueAt (0 , 'data ' , $ object , $ constraint1 , 'group1 ' );
179
175
$ this ->expectValidateValueAt (1 , 'data ' , $ object , $ constraint2 , 'group2 ' );
@@ -361,9 +357,8 @@ public function testHandleGroupSequenceValidationGroups()
361
357
{
362
358
$ object = new \stdClass ();
363
359
$ options = ['validation_groups ' => new GroupSequence (['group1 ' , 'group2 ' ])];
364
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
365
- ->setData ($ object )
366
- ->getForm ();
360
+ $ form = $ this ->getCompoundForm ($ object , $ options );
361
+ $ form ->submit ([]);
367
362
368
363
$ this ->expectValidateAt (0 , 'data ' , $ object , new GroupSequence (['group1 ' , 'group2 ' ]));
369
364
$ this ->expectValidateAt (1 , 'data ' , $ object , new GroupSequence (['group1 ' , 'group2 ' ]));
@@ -377,9 +372,8 @@ public function testHandleCallbackValidationGroups()
377
372
{
378
373
$ object = new \stdClass ();
379
374
$ options = ['validation_groups ' => [$ this , 'getValidationGroups ' ]];
380
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
381
- ->setData ($ object )
382
- ->getForm ();
375
+ $ form = $ this ->getCompoundForm ($ object , $ options );
376
+ $ form ->submit ([]);
383
377
384
378
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
385
379
@@ -392,9 +386,8 @@ public function testDontExecuteFunctionNames()
392
386
{
393
387
$ object = new \stdClass ();
394
388
$ options = ['validation_groups ' => 'header ' ];
395
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
396
- ->setData ($ object )
397
- ->getForm ();
389
+ $ form = $ this ->getCompoundForm ($ object , $ options );
390
+ $ form ->submit ([]);
398
391
399
392
$ this ->expectValidateAt (0 , 'data ' , $ object , ['header ' ]);
400
393
@@ -409,9 +402,8 @@ public function testHandleClosureValidationGroups()
409
402
$ options = ['validation_groups ' => function (FormInterface $ form ) {
410
403
return ['group1 ' , 'group2 ' ];
411
404
}];
412
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
413
- ->setData ($ object )
414
- ->getForm ();
405
+ $ form = $ this ->getCompoundForm ($ object , $ options );
406
+ $ form ->submit ([]);
415
407
416
408
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
417
409
@@ -455,7 +447,7 @@ public function testDontUseValidationGroupOfUnclickedButton()
455
447
->setCompound (true )
456
448
->setDataMapper (new PropertyPathMapper ())
457
449
->getForm ();
458
- $ form = $ this ->getForm ( ' name ' , ' \stdClass ' , [
450
+ $ form = $ this ->getCompoundForm ( $ object , [
459
451
'validation_groups ' => 'form_group ' ,
460
452
'constraints ' => [new Valid ()],
461
453
]);
@@ -465,7 +457,7 @@ public function testDontUseValidationGroupOfUnclickedButton()
465
457
'validation_groups ' => 'button_group ' ,
466
458
]));
467
459
468
- $ form -> setData ( $ object );
460
+ $ parent -> submit ([] );
469
461
470
462
$ this ->expectValidateAt (0 , 'data ' , $ object , ['form_group ' ]);
471
463
@@ -484,10 +476,9 @@ public function testUseInheritedValidationGroup()
484
476
->setDataMapper (new PropertyPathMapper ())
485
477
->getForm ();
486
478
$ formOptions = ['constraints ' => [new Valid ()]];
487
- $ form = $ this ->getBuilder ( ' name ' , ' \stdClass ' , $ formOptions)-> getForm ( );
479
+ $ form = $ this ->getCompoundForm ( $ object , $ formOptions );
488
480
$ parent ->add ($ form );
489
-
179B
490
- $ form ->setData ($ object );
481
+ $ parent ->submit ([]);
491
482
492
483
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group ' ]);
493
484
@@ -506,10 +497,9 @@ public function testUseInheritedCallbackValidationGroup()
506
497
->setDataMapper (new PropertyPathMapper ())
507
498
->getForm ();
508
499
$ formOptions = ['constraints ' => [new Valid ()]];
509
- $ form = $ this ->getBuilder ( ' name ' , ' \stdClass ' , $ formOptions)-> getForm ( );
500
+ $ form = $ this ->getCompoundForm ( $ object , $ formOptions );
510
501
$ parent ->add ($ form );
511
-
512
- $ form ->setData ($ object );
502
+ $ parent ->submit ([]);
513
503
514
504
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
515
505
@@ -523,7 +513,7 @@ public function testUseInheritedClosureValidationGroup()
523
513
$ object = new \stdClass ();
524
514
525
515
$ parentOptions = [
526
- 'validation_groups ' => function (FormInterface $ form ) {
516
+ 'validation_groups ' => function () {
527
517
return ['group1 ' , 'group2 ' ];
528
518
},
529
519
];
@@ -532,10 +522,9 @@ public function testUseInheritedClosureValidationGroup()
532
522
->setDataMapper (new PropertyPathMapper ())
533
523
->getForm ();
534
524
$ formOptions = ['constraints ' => [new Valid ()]];
535
- $ form = $ this ->getBuilder ( ' name ' , ' \stdClass ' , $ formOptions)-> getForm ( );
525
+ $ form = $ this ->getCompoundForm ( $ object , $ formOptions );
536
526
$ parent ->add ($ form );
537
-
538
- $ form ->setData ($ object );
527
+ $ parent ->submit ([]);
539
528
540
529
$ this ->expectValidateAt (0 , 'data ' , $ object , ['group1 ' , 'group2 ' ]);
541
530
@@ -547,9 +536,8 @@ public function testUseInheritedClosureValidationGroup()
547
536
public function testAppendPropertyPath ()
548
537
{
549
538
$ object = new \stdClass ();
550
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' )
551
- ->setData ($ object )
552
- ->getForm ();
539
+ $ form = $ this ->getCompoundForm ($ object );
540
+ $ form ->submit ([]);
553
541
554
542
$ this ->expectValidateAt (0 , 'data ' , $ object , ['Default ' ]);
555
543
@@ -690,6 +678,15 @@ private function getForm($name = 'name', $dataClass = null, array $options = [])
690
678
return $ this ->getBuilder ($ name , $ dataClass , $ options )->getForm ();
691
679
}
692
680
681
+ private function getCompoundForm ($ data , array $ options = [])
682
+ {
683
+ return $ this ->getBuilder ('name ' , \get_class ($ data ), $ options )
684
+ ->setData ($ data )
685
+ ->setCompound (true )
686
+ ->setDataMapper (new PropertyPathMapper ())
687
+ ->getForm ();
688
+ }
689
+
693
690
private function getSubmitButton ($ name = 'name ' , array $ options = [])
694
691
{
695
692
$ builder = new SubmitButtonBuilder ($ name , $ options );
0 commit comments