File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed
src/Symfony/Component/Form Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -156,3 +156,4 @@ CHANGELOG
156
156
consumed by HTML5 browsers, if the widget is "single_text"
157
157
* deprecated the options "data_timezone" and "user_timezone" in DateType, DateTimeType and TimeType
158
158
and renamed them to "model_timezone" and "view_timezone"
159
+ * fixed: TransformationFailedExceptions thrown in the model transformer are now caught by the form
Original file line number Diff line number Diff line change @@ -544,11 +544,7 @@ public function bind($submittedData)
544
544
try {
545
545
// Normalize data to unified representation
546
546
$ normData = $ this ->viewToNorm ($ viewData );
547
- $ synchronized = true ;
548
- } catch (TransformationFailedException $ e ) {
549
- }
550
547
551
- if ($ synchronized ) {
552
548
// Hook to change content of the data into the normalized
553
549
// representation
554
550
$ event = new FormEvent ($ this , $ normData );
@@ -560,6 +556,9 @@ public function bind($submittedData)
560
556
// Synchronize representations - must not change the content!
561
557
$ modelData = $ this ->normToModel ($ normData );
562
558
$ viewData = $ this ->normToView ($ normData );
559
+
560
+ $ synchronized = true ;
561
+ } catch (TransformationFailedException $ e ) {
563
562
}
564
563
565
564
$ this ->bound = true ;
Original file line number Diff line number Diff line change @@ -480,7 +480,7 @@ public function testSynchronizedAfterBinding()
480
480
$ this ->assertTrue ($ this ->form ->isSynchronized ());
481
481
}
482
482
483
- public function testNotSynchronizedIfTransformationFailed ()
483
+ public function testNotSynchronizedIfViewReverseTransformationFailed ()
484
484
{
485
485
$ transformer = $ this ->getDataTransformer ();
486
486
$ transformer ->expects ($ this ->once ())
@@ -496,6 +496,22 @@ public function testNotSynchronizedIfTransformationFailed()
496
496
$ this ->assertFalse ($ form ->isSynchronized ());
497
497
}
498
498
499
+ public function testNotSynchronizedIfModelReverseTransformationFailed ()
500
+ {
501
+ $ transformer = $ this ->getDataTransformer ();
502
+ $ transformer ->expects ($ this ->once ())
503
+ ->method ('reverseTransform ' )
504
+ ->will ($ this ->throwException (new TransformationFailedException ()));
505
+
506
+ $ form = $ this ->getBuilder ()
507
+ ->addModelTransformer ($ transformer )
508
+ ->getForm ();
509
+
510
+ $ form ->bind ('foobar ' );
511
+
512
+ $ this ->assertFalse ($ form ->isSynchronized ());
513
+ }
514
+
499
515
public function testEmptyDataCreatedBeforeTransforming ()
500
516
{
501
517
$ form = $ this ->getBuilder ()
You can’t perform that action at this time.
0 commit comments