Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 039980c

Browse files
committed
minor #17886 [WIP] [3.0] [Form] fix tests added by #17760 by removing choices_as_values (HeahDude)
This PR was squashed before being merged into the 3.0 branch (closes #17886). Discussion ---------- [WIP] [3.0] [Form] fix tests added by #17760 by removing `choices_as_values` | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | not yet | Fixed tickets | n/a | License | MIT | Doc PR | - - [x] Wait for #17760 being merged in 3.0 Commits ------- 03a7705 [WIP] [3.0] [Form] fix tests added by #17760 by removing
2 parents 88e6e3d + 03a7705 commit 039980c

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
148148
// with the string value so it can be matched in
149149
// {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper::mapDataToForms()}
150150
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
151-
$choiceList = $event->getForm()->getConfig()->getOption('choice_list');
151+
$choiceList = $event->getForm()->getConfig()->getAttribute('choice_list');
152152
$value = current($choiceList->getValuesForChoices(array($event->getData())));
153153
$event->setData((string) $value);
154154
});

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
3030
'n/a' => '',
3131
);
3232

33-
private $numericChoicesFlipped = array(
34-
0 => 'Bernhard',
35-
1 => 'Fabien',
36-
2 => 'Kris',
37-
3 => 'Jon',
38-
4 => 'Roman',
39-
);
40-
4133
private $objectChoices;
4234

4335
protected $groupedChoices = array(
@@ -110,9 +102,8 @@ public function testExpandedChoicesOptionsTurnIntoChildren()
110102

111103
public function testChoiceListWithScalarValues()
112104
{
113-
$view = $this->factory->create('choice', null, array(
105+
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
114106
'choices' => $this->scalarChoices,
115-
'choices_as_values' => true,
116107
))->createView();
117108

118109
$this->assertSame('1', $view->vars['choices'][0]->value);
@@ -125,19 +116,17 @@ public function testChoiceListWithScalarValues()
125116

126117
public function testChoiceListWithScalarValuesAndFalseAsPreSetData()
127118
{
128-
$view = $this->factory->create('choice', false, array(
119+
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
129120
'choices' => $this->scalarChoices,
130-
'choices_as_values' => true,
131121
))->createView();
132122

133123
$this->assertTrue($view->vars['is_selected']($view->vars['choices'][1]->value, $view->vars['value']), 'False value should be pre selected');
134124
}
135125

136126
public function testExpandedChoiceListWithScalarValues()
137127
{
138-
$view = $this->factory->create('choice', null, array(
128+
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
139129
'choices' => $this->scalarChoices,
140-
'choices_as_values' => true,
141130
'expanded' => true,
142131
))->createView();
143132

@@ -148,9 +137,8 @@ public function testExpandedChoiceListWithScalarValues()
148137

149138
public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData()
150139
{
151-
$view = $this->factory->create('choice', false, array(
140+
$view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
152141
'choices' => $this->scalarChoices,
153-
'choices_as_values' => true,
154142
'expanded' => true,
155143
))->createView();
156144

@@ -217,7 +205,7 @@ public function testPlaceholderNotPresentIfEmptyChoice()
217205

218206
public function testPlaceholderWithBooleanChoices()
219207
{
220-
$form = $this->factory->create('choice', null, array(
208+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
221209
'multiple' => false,
222210
'expanded' => false,
223211
'required' => false,
@@ -226,7 +214,6 @@ public function testPlaceholderWithBooleanChoices()
226214
'No' => false,
227215
),
228216
'placeholder' => 'Select an option',
229-
'choices_as_values' => true,
230217
));
231218

232219
$view = $form->createView();
@@ -239,7 +226,7 @@ public function testPlaceholderWithBooleanChoices()
239226

240227
public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
241228
{
242-
$form = $this->factory->create('choice', false, array(
229+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
243230
'multiple' => false,
244231
'expanded' => false,
245232
'required' => false,
@@ -248,7 +235,6 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
248235
'No' => false,
249236
),
250237
'placeholder' => 'Select an option',
251-
'choices_as_values' => true,
252238
));
253239

254240
$view = $form->createView();
@@ -261,7 +247,7 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
261247

262248
public function testPlaceholderWithExpandedBooleanChoices()
263249
{
264-
$form = $this->factory->create('choice', null, array(
250+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
265251
'multiple' => false,
266252
'expanded' => true,
267253
'required' => false,
@@ -270,7 +256,6 @@ public function testPlaceholderWithExpandedBooleanChoices()
270256
'No' => false,
271257
),
272258
'placeholder' => 'Select an option',
273-
'choices_as_values' => true,
274259
));
275260

276261
$this->assertTrue(isset($form['placeholder']), 'Placeholder should be set');
@@ -286,7 +271,7 @@ public function testPlaceholderWithExpandedBooleanChoices()
286271

287272
public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData()
288273
{
289-
$form = $this->factory->create('choice', false, array(
274+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array(
290275
'multiple' => false,
291276
'expanded' => true,
292277
'required' => false,
@@ -295,7 +280,6 @@ public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetDat
295280
'No' => false,
296281
),
297282
'placeholder' => 'Select an option',
298-
'choices_as_values' => true,
299283
));
300284

301285
$this->assertTrue(isset($form['placeholder']), 'Placeholder should be set');

0 commit comments

Comments
 (0)