Skip to content

Commit 8e3c1d1

Browse files
Merge branch '2.7' into 2.8
* 2.7: (70 commits) [travis] Use container-based infrastructure [HttpKernel] use ConfigCache::getPath() method when it exists [PropertyAccess] Fix setting public property on a class having a magic getter [Routing] Display file which contain deprecated option ContainerInterface: unused exception dropped bumped Symfony version to 2.6.8 updated VERSION for 2.6.7 updated CHANGELOG for 2.6.7 bumped Symfony version to 2.3.29 updated VERSION for 2.3.28 update CONTRIBUTORS for 2.3.28 updated CHANGELOG for 2.3.28 [Debug] Fixed ClassNotFoundFatalErrorHandlerTest [SecurityBundle] use access decision constants in config [SecurityBundle] use session auth constants in config PhpDoc fix in AbstractRememberMeServices [Filesystem] Simplified an if statement [SecurityBundle] Use Enum Nodes Instead Of Scalar [Debug 2.3] Fix test for PHP7 [HttpKernel] Check if "symfony/proxy-manager-bridge" package is installed ... Conflicts: src/Symfony/Bundle/DebugBundle/composer.json src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Component/Form/README.md src/Symfony/Component/Intl/README.md src/Symfony/Component/Security/README.md src/Symfony/Component/Translation/Loader/CsvFileLoader.php src/Symfony/Component/Translation/Loader/IniFileLoader.php src/Symfony/Component/Translation/Loader/MoFileLoader.php src/Symfony/Component/Translation/Loader/PhpFileLoader.php src/Symfony/Component/Translation/Loader/PoFileLoader.php src/Symfony/Component/Translation/Loader/YamlFileLoader.php src/Symfony/Component/Translation/README.md src/Symfony/Component/Translation/Translator.php src/Symfony/Component/Validator/README.md
2 parents ff7674f + bfadb84 commit 8e3c1d1

File tree

10 files changed

+98
-32
lines changed

10 files changed

+98
-32
lines changed

Extension/Core/DataTransformer/ChoiceToValueTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function reverseTransform($value)
4646
$choices = $this->choiceList->getChoicesForValues(array((string) $value));
4747

4848
if (1 !== count($choices)) {
49+
if (null === $value || '' === $value) {
50+
return;
51+
}
52+
4953
throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
5054
}
5155

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;

FormEvents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
/**
1717
* To learn more about how form events work check the documentation
18-
* entry at {@link http://symfony.com/doc/any/components/form/form_events.html}.
18+
* entry at {@link https://symfony.com/doc/any/components/form/form_events.html}.
1919
*
2020
* To learn how to dynamically modify forms using events check the cookbook
21-
* entry at {@link http://symfony.com/doc/any/cookbook/form/dynamic_form_modification.html}.
21+
* entry at {@link https://symfony.com/doc/any/cookbook/form/dynamic_form_modification.html}.
2222
*
2323
* @author Bernhard Schussek <[email protected]>
2424
*/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/FormServiceProvid
1414

1515
Documentation:
1616

17-
http://symfony.com/doc/2.8/book/forms.html
17+
https://symfony.com/doc/2.8/book/forms.html
1818

1919
Resources
2020
---------

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/Core/Type/ChoiceTypeTest.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ public function testSubmitSingleNonExpanded()
240240

241241
$this->assertEquals('b', $form->getData());
242242
$this->assertEquals('b', $form->getViewData());
243+
$this->assertTrue($form->isSynchronized());
243244
}
244245

245246
public function testSubmitSingleNonExpandedInvalidChoice()
@@ -269,6 +270,7 @@ public function testSubmitSingleNonExpandedNull()
269270

270271
$this->assertNull($form->getData());
271272
$this->assertSame('', $form->getViewData());
273+
$this->assertTrue($form->isSynchronized());
272274
}
273275

274276
// In edge cases (for example, when choices are loaded dynamically by a
@@ -286,6 +288,7 @@ public function testSubmitSingleNonExpandedNullNoChoices()
286288

287289
$this->assertNull($form->getData());
288290
$this->assertSame('', $form->getViewData());
291+
$this->assertTrue($form->isSynchronized());
289292
}
290293

291294
public function testSubmitSingleNonExpandedEmpty()
@@ -300,6 +303,27 @@ public function testSubmitSingleNonExpandedEmpty()
300303

301304
$this->assertNull($form->getData());
302305
$this->assertSame('', $form->getViewData());
306+
$this->assertTrue($form->isSynchronized());
307+
}
308+
309+
public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice()
310+
{
311+
$form = $this->factory->create('choice', null, array(
312+
'multiple' => false,
313+
'expanded' => false,
314+
'choices' => array(
315+
'EMPTY_CHOICE' => 'Empty',
316+
),
317+
'choice_value' => function () {
318+
return '';
319+
},
320+
));
321+
322+
$form->submit('');
323+
324+
$this->assertSame('EMPTY_CHOICE', $form->getData());
325+
$this->assertSame('', $form->getViewData());
326+
$this->assertTrue($form->isSynchronized());
303327
}
304328

305329
// In edge cases (for example, when choices are loaded dynamically by a
@@ -317,6 +341,7 @@ public function testSubmitSingleNonExpandedEmptyNoChoices()
317341

318342
$this->assertNull($form->getData());
319343
$this->assertSame('', $form->getViewData());
344+
$this->assertTrue($form->isSynchronized());
320345
}
321346

322347
public function testSubmitSingleNonExpandedFalse()
@@ -331,6 +356,7 @@ public function testSubmitSingleNonExpandedFalse()
331356

332357
$this->assertNull($form->getData());
333358
$this->assertSame('', $form->getViewData());
359+
$this->assertTrue($form->isSynchronized());
334360
}
335361

336362
// In edge cases (for example, when choices are loaded dynamically by a
@@ -348,6 +374,7 @@ public function testSubmitSingleNonExpandedFalseNoChoices()
348374

349375
$this->assertNull($form->getData());
350376
$this->assertSame('', $form->getViewData());
377+
$this->assertTrue($form->isSynchronized());
351378
}
352379

353380
public function testSubmitSingleNonExpandedObjectChoices()
@@ -366,6 +393,7 @@ public function testSubmitSingleNonExpandedObjectChoices()
366393

367394
$this->assertEquals($this->objectChoices[1], $form->getData());
368395
$this->assertEquals('2', $form->getViewData());
396+
$this->assertTrue($form->isSynchronized());
369397
}
370398

371399
/**
@@ -392,6 +420,7 @@ public function testLegacySubmitSingleNonExpandedObjectChoices()
392420

393421
$this->assertEquals($this->objectChoices[1], $form->getData());
394422
$this->assertEquals('2', $form->getViewData());
423+
$this->assertTrue($form->isSynchronized());
395424
}
396425

397426
public function testSubmitMultipleNonExpanded()
@@ -406,6 +435,7 @@ public function testSubmitMultipleNonExpanded()
406435

407436
$this->assertEquals(array('a', 'b'), $form->getData());
408437
$this->assertEquals(array('a', 'b'), $form->getViewData());
438+
$this->assertTrue($form->isSynchronized());
409439
}
410440

411441
public function testSubmitMultipleNonExpandedEmpty()
@@ -420,6 +450,7 @@ public function testSubmitMultipleNonExpandedEmpty()
420450

421451
$this->assertSame(array(), $form->getData());
422452
$this->assertSame(array(), $form->getViewData());
453+
$this->assertTrue($form->isSynchronized());
423454
}
424455

425456
// In edge cases (for example, when choices are loaded dynamically by a
@@ -437,6 +468,7 @@ public function testSubmitMultipleNonExpandedEmptyNoChoices()
437468

438469
$this->assertSame(array(), $form->getData());
439470
$this->assertSame(array(), $form->getViewData());
471+
$this->assertTrue($form->isSynchronized());
440472
}
441473

442474
public function testSubmitMultipleNonExpandedInvalidScalarChoice()
@@ -484,6 +516,7 @@ public function testSubmitMultipleNonExpandedObjectChoices()
484516

485517
$this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData());
486518
$this->assertEquals(array('2', '3'), $form->getViewData());
519+
$this->assertTrue($form->isSynchronized());
487520
}
488521

489522
/**
@@ -509,6 +542,7 @@ public function testLegacySubmitMultipleNonExpandedObjectChoices()
509542

510543
$this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData());
511544
$this->assertEquals(array('2', '3'), $form->getViewData());
545+
$this->assertTrue($form->isSynchronized());
512546
}
513547

514548
public function testSubmitSingleExpandedRequired()
@@ -933,6 +967,8 @@ public function testSubmitSingleExpandedWithEmptyChild()
933967
$form->submit('');
934968

935969
$this->assertNull($form->getData());
970+
$this->assertTrue($form->isSynchronized());
971+
936972
$this->assertTrue($form[0]->getData());
937973
$this->assertFalse($form[1]->getData());
938974
$this->assertSame('', $form[0]->getViewData());
@@ -953,6 +989,8 @@ public function testSubmitSingleExpandedObjectChoices()
953989
$form->submit('2');
954990

955991
$this->assertSame($this->objectChoices[1], $form->getData());
992+
$this->assertTrue($form->isSynchronized());
993+
956994
$this->assertFalse($form[0]->getData());
957995
$this->assertTrue($form[1]->getData());
958996
$this->assertFalse($form[2]->getData());
@@ -987,6 +1025,8 @@ public function testLegacySubmitSingleExpandedObjectChoices()
9871025
$form->submit('2');
9881026

9891027
$this->assertSame($this->objectChoices[1], $form->getData());
1028+
$this->assertTrue($form->isSynchronized());
1029+
9901030
$this->assertFalse($form[0]->getData());
9911031
$this->assertTrue($form[1]->getData());
9921032
$this->assertFalse($form[2]->getData());
@@ -1010,6 +1050,8 @@ public function testSubmitSingleExpandedNumericChoices()
10101050
$form->submit('1');
10111051

10121052
$this->assertSame(1, $form->getData());
1053+
$this->assertTrue($form->isSynchronized());
1054+
10131055
$this->assertFalse($form[0]->getData());
10141056
$this->assertTrue($form[1]->getData());
10151057
$this->assertFalse($form[2]->getData());
@@ -1114,6 +1156,8 @@ public function testSubmitMultipleExpandedEmpty()
11141156
$form->submit(array());
11151157

11161158
$this->assertSame(array(), $form->getData());
1159+
$this->assertTrue($form->isSynchronized());
1160+
11171161
$this->assertFalse($form[0]->getData());
11181162
$this->assertFalse($form[1]->getData());
11191163
$this->assertFalse($form[2]->getData());
@@ -1140,6 +1184,7 @@ public function testSubmitMultipleExpandedEmptyNoChoices()
11401184
$form->submit(array());
11411185

11421186
$this->assertSame(array(), $form->getData());
1187+
$this->assertTrue($form->isSynchronized());
11431188
}
11441189

11451190
public function testSubmitMultipleExpandedWithEmptyChild()
@@ -1157,6 +1202,8 @@ public function testSubmitMultipleExpandedWithEmptyChild()
11571202
$form->submit(array('', '2'));
11581203

11591204
$this->assertSame(array('', 2), $form->getData());
1205+
$this->assertTrue($form->isSynchronized());
1206+
11601207
$this->assertTrue($form[0]->getData());
11611208
$this->assertFalse($form[1]->getData());
11621209
$this->assertTrue($form[2]->getData());
@@ -1179,6 +1226,8 @@ public function testSubmitMultipleExpandedObjectChoices()
11791226
$form->submit(array('1', '2'));
11801227

11811228
$this->assertSame(array($this->objectChoices[0], $this->objectChoices[1]), $form->getData());
1229+
$this->assertTrue($form->isSynchronized());
1230+
11821231
$this->assertTrue($form[0]->getData());
11831232
$this->assertTrue($form[1]->getData());
11841233
$this->assertFalse($form[2]->getData());
@@ -1213,6 +1262,8 @@ public function testLegacySubmitMultipleExpandedObjectChoices()
12131262
$form->submit(array('1', '2'));
12141263

12151264
$this->assertSame(array($this->objectChoices[0], $this->objectChoices[1]), $form->getData());
1265+
$this->assertTrue($form->isSynchronized());
1266+
12161267
$this->assertTrue($form[0]->getData());
12171268
$this->assertTrue($form[1]->getData());
12181269
$this->assertFalse($form[2]->getData());
@@ -1236,6 +1287,8 @@ public function testSubmitMultipleExpandedNumericChoices()
12361287
$form->submit(array('1', '2'));
12371288

12381289
$this->assertSame(array(1, 2), $form->getData());
1290+
$this->assertTrue($form->isSynchronized());
1291+
12391292
$this->assertFalse($form[0]->getData());
12401293
$this->assertTrue($form[1]->getData());
12411294
$this->assertTrue($form[2]->getData());
@@ -1264,6 +1317,7 @@ public function testSetDataSingleNonExpandedAcceptsBoolean()
12641317

12651318
$this->assertFalse($form->getData());
12661319
$this->assertEquals('0', $form->getViewData());
1320+
$this->assertTrue($form->isSynchronized());
12671321
}
12681322

12691323
public function testSetDataMultipleNonExpandedAcceptsBoolean()
@@ -1278,6 +1332,7 @@ public function testSetDataMultipleNonExpandedAcceptsBoolean()
12781332

12791333
$this->assertEquals(array(false, true), $form->getData());
12801334
$this->assertEquals(array('0', '1'), $form->getViewData());
1335+
$this->assertTrue($form->isSynchronized());
12811336
}
12821337

12831338
public function testPassRequiredToView()
@@ -1344,7 +1399,7 @@ public function testChoiceTranslationDomainWithTrueValueToView()
13441399
$this->assertNull($view->vars['choice_translation_domain']);
13451400
}
13461401

1347-
public function testDefaulChoiceTranslationDomainIsSameAsTranslationDomainToView()
1402+
public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToView()
13481403
{
13491404
$form = $this->factory->create('choice', null, array(
13501405
'choices' => $this->choices,

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' => "''",

0 commit comments

Comments
 (0)