Skip to content

Commit 92fe4af

Browse files
committed
Merge branch '2.6' into 2.7
* 2.6: [Validator] Property paths starting with 0 are broken. Fixed test [2.6][Validator] Fix Interface reference in docblock Fix getOrigin Conflicts: src/Symfony/Component/Validator/ValidatorInterface.php
2 parents b75a70c + aa6ac87 commit 92fe4af

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

Form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,11 @@ public function bind($submittedData)
695695
*/
696696
public function addError(FormError $error)
697697
{
698-
if ($this->parent && $this->config->getErrorBubbling()) {
699-
if (null === $error->getOrigin()) {
700-
$error->setOrigin($this);
701-
}
698+
if (null === $error->getOrigin()) {
699+
$error->setOrigin($this);
700+
}
702701

702+
if ($this->parent && $this->config->getErrorBubbling()) {
703703
$this->parent->addError($error);
704704
} else {
705705
$this->errors[] = $error;

Tests/AbstractRequestHandlerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ public function testAddFormErrorIfPostMaxSizeExceeded($contentLength, $iniMax, $
329329
$this->requestHandler->handleRequest($form, $this->request);
330330

331331
if ($shouldFail) {
332-
$errors = array(new FormError($options['post_max_size_message'], null, $errorParams));
332+
$error = new FormError($options['post_max_size_message'], null, $errorParams);
333+
$error->setOrigin($form);
333334

334-
$this->assertEquals($errors, iterator_to_array($form->getErrors()));
335+
$this->assertEquals(array($error), iterator_to_array($form->getErrors()));
335336
$this->assertTrue($form->isSubmitted());
336337
} else {
337338
$this->assertCount(0, $form->getErrors());

Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ public function testsTranslateCustomErrorMessage()
393393
));
394394

395395
$errors = $form->getErrors();
396+
$expected = new FormError('[trans]Foobar[/trans]');
397+
$expected->setOrigin($form);
396398

397399
$this->assertGreaterThan(0, count($errors));
398-
$this->assertEquals(new FormError('[trans]Foobar[/trans]'), $errors[0]);
400+
$this->assertEquals($expected, $errors[0]);
399401
}
400402
}

Tests/Extension/DataCollector/FormDataExtractorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public function testExtractSubmittedDataStoresErrors()
319319
'norm' => "'Foobar'",
320320
),
321321
'errors' => array(
322-
array('message' => 'Invalid!', 'origin' => null, 'trace' => array()),
322+
array('message' => 'Invalid!', 'origin' => spl_object_hash($form), 'trace' => array()),
323323
),
324324
'synchronized' => 'true',
325325
), $this->dataExtractor->extractSubmittedData($form));
@@ -360,7 +360,7 @@ public function testExtractSubmittedDataStoresErrorCause()
360360
'norm' => "'Foobar'",
361361
),
362362
'errors' => array(
363-
array('message' => 'Invalid!', 'origin' => null, 'trace' => array(
363+
array('message' => 'Invalid!', 'origin' => spl_object_hash($form), 'trace' => array(
364364
array(
365365
'class' => "'Exception'",
366366
'message' => "''",

Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\Exception\TransformationFailedException;
1616
use Symfony\Component\Form\CallbackTransformer;
1717
use Symfony\Component\Form\Form;
18+
use Symfony\Component\Form\FormInterface;
1819
use Symfony\Component\Form\FormConfigBuilder;
1920
use Symfony\Component\Form\FormError;
2021
use Symfony\Component\PropertyAccess\PropertyPath;
@@ -110,9 +111,12 @@ protected function getConstraintViolation($propertyPath)
110111
/**
111112
* @return FormError
112113
*/
113-
protected function getFormError(ConstraintViolationInterface $violation)
114+
protected function getFormError(ConstraintViolationInterface $violation, FormInterface $form)
114115
{
115-
return new FormError($this->message, $this->messageTemplate, $this->params, null, $violation);
116+
$error = new FormError($this->message, $this->messageTemplate, $this->params, null, $violation);
117+
$error->setOrigin($form);
118+
119+
return $error;
116120
}
117121

118122
public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
@@ -130,7 +134,7 @@ public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
130134
$this->mapper->mapViolation($violation, $parent);
131135

132136
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
133-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $child->getName().' should have an error, but has none');
137+
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $child->getName().' should have an error, but has none');
134138
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
135139
}
136140

@@ -159,7 +163,7 @@ public function testFollowDotRules()
159163
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
160164
$this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one');
161165
$this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one');
162-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandGrandChild->getErrors()), $grandGrandChild->getName().' should have an error, but has none');
166+
$this->assertEquals(array($this->getFormError($violation, $grandGrandChild)), iterator_to_array($grandGrandChild->getErrors()), $grandGrandChild->getName().' should have an error, but has none');
163167
}
164168

165169
public function testAbortMappingIfNotSynchronized()
@@ -800,17 +804,17 @@ public function testDefaultErrorMapping($target, $childName, $childPath, $grandC
800804
$this->mapper->mapViolation($violation, $parent);
801805

802806
if (self::LEVEL_0 === $target) {
803-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
807+
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
804808
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
805809
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
806810
} elseif (self::LEVEL_1 === $target) {
807811
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
808-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
812+
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
809813
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
810814
} else {
811815
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
812816
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
813-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
817+
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
814818
}
815819
}
816820

@@ -1274,17 +1278,17 @@ public function testCustomDataErrorMapping($target, $mapFrom, $mapTo, $childName
12741278
}
12751279

12761280
if (self::LEVEL_0 === $target) {
1277-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
1281+
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
12781282
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
12791283
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
12801284
} elseif (self::LEVEL_1 === $target) {
12811285
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
1282-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
1286+
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
12831287
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
12841288
} else {
12851289
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
12861290
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
1287-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
1291+
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
12881292
}
12891293
}
12901294

@@ -1458,24 +1462,24 @@ public function testCustomFormErrorMapping($target, $mapFrom, $mapTo, $errorName
14581462

14591463
if (self::LEVEL_0 === $target) {
14601464
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
1461-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
1465+
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
14621466
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
14631467
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
14641468
} elseif (self::LEVEL_1 === $target) {
14651469
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
14661470
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
1467-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
1471+
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
14681472
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
14691473
} elseif (self::LEVEL_1B === $target) {
1470-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($errorChild->getErrors()), $errorName.' should have an error, but has none');
1474+
$this->assertEquals(array($this->getFormError($violation, $errorChild)), iterator_to_array($errorChild->getErrors()), $errorName.' should have an error, but has none');
14711475
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
14721476
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
14731477
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
14741478
} else {
14751479
$this->assertCount(0, $errorChild->getErrors(), $errorName.' should not have an error, but has one');
14761480
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
14771481
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
1478-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
1482+
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
14791483
}
14801484
}
14811485

@@ -1522,17 +1526,17 @@ public function testErrorMappingForFormInheritingParentData($target, $childName,
15221526
$this->mapper->mapViolation($violation, $parent);
15231527

15241528
if (self::LEVEL_0 === $target) {
1525-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
1529+
$this->assertEquals(array($this->getFormError($violation, $parent)), iterator_to_array($parent->getErrors()), $parent->getName().' should have an error, but has none');
15261530
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
15271531
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
15281532
} elseif (self::LEVEL_1 === $target) {
15291533
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
1530-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
1534+
$this->assertEquals(array($this->getFormError($violation, $child)), iterator_to_array($child->getErrors()), $childName.' should have an error, but has none');
15311535
$this->assertCount(0, $grandChild->getErrors(), $grandChildName.' should not have an error, but has one');
15321536
} else {
15331537
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
15341538
$this->assertCount(0, $child->getErrors(), $childName.' should not have an error, but has one');
1535-
$this->assertEquals(array($this->getFormError($violation)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
1539+
$this->assertEquals(array($this->getFormError($violation, $grandChild)), iterator_to_array($grandChild->getErrors()), $grandChildName.' should have an error, but has none');
15361540
}
15371541
}
15381542
}

0 commit comments

Comments
 (0)