10000 [Form] Fixed TransformationFailedExceptions to be caught in the model… · symfony/symfony@c919b81 · GitHub
[go: up one dir, main page]

Skip to content

Commit c919b81

Browse files
committed
[Form] Fixed TransformationFailedExceptions to be caught in the model transformers
1 parent f06203a commit c919b81

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ CHANGELOG
156156
consumed by HTML5 browsers, if the widget is "single_text"
157157
* deprecated the options "data_timezone" and "user_timezone" in DateType, DateTimeType and TimeType
158158
and renamed them to "model_timezone" and "view_timezone"
159+
* fixed: TransformationFailedExceptions thrown in the model transformer are now caught by the form

src/Symfony/Component/Form/Form.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,7 @@ public function bind($submittedData)
544544
try {
545545
// Normalize data to unified representation
546546
$normData = $this->viewToNorm($viewData);
547-
$synchronized = true;
548-
} catch (TransformationFailedException $e) {
549-
}
550547

551-
if ($synchronized) {
552548
// Hook to change content of the data into the normalized
553549
// representation
554550
$event = new FormEvent($this, $normData);
@@ -560,6 +556,9 @@ public function bind($submittedData)
560556
// Synchronize representations - must not change the content!
561557
$modelData = $this->normToModel($normData);
562558
$viewData = $this->normToView($normData);
559+
560+
$synchronized = true;
561+
} catch (TransformationFailedException $e) {
563562
}
564563

565564
$this->bound = true;

src/Symfony/Component/Form/Tests/SimpleFormTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public function testSynchronizedAfterBinding()
480480
$this->assertTrue($this->form->isSynchronized());
481481
}
482482

483-
public function testNotSynchronizedIfTransformationFailed()
483+
public function testNotSynchronizedIfViewReverseTransformationFailed()
484484
{
485485
$transformer = $this->getDataTransformer();
486486
$transformer->expects($this->once())
@@ -496,6 +496,22 @@ public function testNotSynchronizedIfTransformationFailed()
496496
$this->assertFalse($form->isSynchronized());
497497
}
498498

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+
499515
public function testEmptyDataCreatedBeforeTransforming()
500516
{
501517
$form = $this->getBuilder()

0 commit comments

Comments
 (0)
0