Skip to content

Commit 4bb9470

Browse files
Merge branch '2.7' into 2.8
* 2.7: Lighten tests output by removing composer suggestions CS: Remove invisible chars Disable resource tracking if the config component is missing [EventDispatcher] Remove unneded count() Fix tests expecting a valid date [Console] Fix table cell styling [Console] Revised exception rendering [WebProfilerBundle] Normalize whitespace in exceptions passed in headers Disable color support detection for tests [Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set
2 parents 3a8dd4a + 196050a commit 4bb9470

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

Extension/Core/DataTransformer/PercentToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function reverseTransform($value)
120120

121121
$formatter = $this->getNumberFormatter();
122122
// replace normal spaces so that the formatter can read them
123-
$value = $formatter->parse(str_replace(' ', ' ', $value));
123+
$value = $formatter->parse(str_replace(' ', "\xc2\xa0", $value));
124124

125125
if (intl_is_failure($formatter->getErrorCode())) {
126126
throw new TransformationFailedException($formatter->getErrorMessage());

Extension/Validator/ValidatorExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($validator)
6060

6161
public function loadTypeGuesser()
6262
{
63-
// 2.5 API
63+
// 2.5 API
6464
if ($this->validator instanceof ValidatorInterface) {
6565
return new ValidatorTypeGuesser($this->validator);
6666
}

Form.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ public function getData()
408408
}
409409

410410
if (!$this->defaultDataSet) {
411+
if ($this->lockSetData) {
412+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.');
413+
}
414+
411415
$this->setData($this->config->getData());
412416
}
413417

@@ -428,6 +432,10 @@ public function getNormData()
428432
}
429433

430434
if (!$this->defaultDataSet) {
435+
if ($this->lockSetData) {
436+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.');
437+
}
438+
431439
$this->setData($this->config->getData());
432440
}
433441

@@ -448,6 +456,10 @@ public function getViewData()
448456
}
449457

450458
if (!$this->defaultDataSet) {
459+
if ($this->lockSetData) {
460+
throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.');
461+
}
462+
451463
$this->setData($this->config->getData());
452464
}
453465

Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function testIsSynchronizedReturnsTrueIfChoiceAndCompletelyFilled()
608608
));
609609

610610
$form->submit(array(
611-
'day' => '0',
611+
'day' => '1',
612612
'month' => '6',
613613
'year' => '2010',
614614
));

Tests/SimpleFormTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ public function testViewDataMustBeObjectIfDataClassIsSet()
903903

904904
/**
905905
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
906+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.
906907
*/
907908
public function testSetDataCannotInvokeItself()
908909
{
@@ -1084,6 +1085,51 @@ public function testCustomOptionsResolver()
10841085
$fooType->setDefaultOptions($resolver);
10851086
}
10861087

1088+
/**
1089+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1090+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.
1091+
*/
1092+
public function testCannotCallGetDataInPreSetDataListenerIfDataHasNotAlreadyBeenSet()
1093+
{
1094+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1095+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1096+
$event->getForm()->getData();
1097+
});
1098+
$form = new Form($config);
1099+
1100+
$form->setData('foo');
1101+
}
1102+
1103+
/**
1104+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1105+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.
1106+
*/
1107+
public function testCannotCallGetNormDataInPreSetDataListener()
1108+
{
1109+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1110+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1111+
$event->getForm()->getNormData();
1112+
});
1113+
$form = new Form($config);
1114+
1115+
$form->setData('foo');
1116+
}
1117+
1118+
/**
1119+
* @expectedException \Symfony\Component\Form\Exception\RuntimeException
1120+
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.
1121+
*/
1122+
public function testCannotCallGetViewDataInPreSetDataListener()
1123+
{
1124+
$config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
1125+
$config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
1126+
$event->getForm()->getViewData();
1127+
});
1128+
$form = new Form($config);
1129+
1130+
$form->setData('foo');
1131+
}
1132+
10871133
protected function createForm()
10881134
{
10891135
return $this->getBuilder()->getForm();

0 commit comments

Comments
 (0)