Skip to content

Commit 3880f76

Browse files
Merge branch '2.7' into 2.8
* 2.7: Various fixes esp. on Windows Fix the validation of form resources to register the default theme Fix the retrieval of the value with property path when using a loader [appveyor] minor enhancements [Process] Disable failing tests on Windows [Translation] Fix the string casting in the XliffFileLoader Windows and Intl fixes Add appveyor.yml for C.I. on Windows [VarDumper] fixed HtmlDumper to target specific the head tag [travis] merge php: nightly and deps=high test-matrix lines consistently use str_replace to unify directory separators Support omitting the <target> node in an .xlf file. Fix the handling of values for multiple choice types moved PHP nightly to PHP 7.0 [Security] Add missing docblock in PreAuthenticatedToken Conflicts: .travis.yml
2 parents 5ec8e1d + 69707f5 commit 3880f76

File tree

7 files changed

+81
-9
lines changed

7 files changed

+81
-9
lines changed

ChoiceList/ArrayChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getValuesForChoices(array $choices)
155155
$givenValues = array();
156156

157157
foreach ($choices as $i => $givenChoice) {
158-
$givenValues[$i] = call_user_func($this->valueCallback, $givenChoice);
158+
$givenValues[$i] = (string) call_user_func($this->valueCallback, $givenChoice);
159159
}
160160

161161
return array_intersect($givenValues, array_keys($this->choices));

ChoiceList/Factory/CachingFactoryDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function generateHash($value, $namespace = '')
6262
});
6363
}
6464

65-
return hash('sha256', $namespace.':'.json_encode($value));
65+
return hash('sha256', $namespace.':'.serialize($value));
6666
}
6767

6868
/**

ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
141141
if ($value instanceof PropertyPath) {
142142
$accessor = $this->propertyAccessor;
143143
$value = function ($choice) use ($accessor, $value) {
144-
return $accessor->getValue($choice, $value);
144+
// The callable may be invoked with a non-object/array value
145+
// when such values are passed to
146+
// ChoiceListInterface::getValuesForChoices(). Handle this case
147+
// so that the call to getValue() doesn't break.
148+
if (is_object($choice) || is_array($choice)) {
149+
return $accessor->getValue($choice, $value);
150+
}
145151
};
146152
}
147153

Extension/Core/Type/DateType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $
275275
$pattern = $formatter->getPattern();
276276
$timezone = $formatter->getTimezoneId();
277277

278-
if ($setTimeZone = method_exists($formatter, 'setTimeZone')) {
278+
if ($setTimeZone = PHP_VERSION_ID >= 50500 || method_exists($formatter, 'setTimeZone')) {
279279
$formatter->setTimeZone('UTC');
280280
} else {
281281
$formatter->setTimeZoneId('UTC');

Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,36 @@ public function testCreateFromLoaderPropertyPath()
9393
$this->assertSame('value', $this->factory->createListFromLoader($loader, 'property'));
9494
}
9595

96+
// https://github.com/symfony/symfony/issues/5494
97+
public function testCreateFromChoicesAssumeNullIfValuePropertyPathUnreadable()
98+
{
99+
$choices = array(null);
100+
101+
$this->decoratedFactory->expects($this->once())
102+
->method('createListFromChoices')
103+
->with($choices, $this->isInstanceOf('\Closure'))
104+
->will($this->returnCallback(function ($choices, $callback) {
105+
return array_map($callback, $choices);
106+
}));
107+
108+
$this->assertSame(array(null), $this->factory->createListFromChoices($choices, 'property'));
109+
}
110+
111+
// https://github.com/symfony/symfony/issues/5494
112+
public function testCreateFromChoiceLoaderAssumeNullIfValuePropertyPathUnreadable()
113+
{
114+
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');
115+
116+
$this->decoratedFactory->expects($this->once())
117+
->method('createListFromLoader')
118+
->with($loader, $this->isInstanceOf('\Closure'))
119+
->will($this->returnCallback(function ($loader, $callback) {
120+
return $callback(null);
121+
}));
122+
123+
$this->assertNull($this->factory->createListFromLoader($loader, 'property'));
124+
}
125+
96126
public function testCreateFromLoaderPropertyPathInstance()
97127
{
98128
$loader = $this->getMock('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface');

Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ public function testTransformWithScale()
9292

9393
public function transformWithRoundingProvider()
9494
{
95-
// Since we test against "de_AT", we need the full implementation
96-
IntlTestHelper::requireFullIntl($this);
97-
98-
\Locale::setDefault('de_AT');
99-
10095
return array(
10196
// towards positive infinity (1.6 -> 2, -1.6 -> -1)
10297
array(0, 1234.5, '1235', NumberToLocalizedStringTransformer::ROUND_CEILING),
@@ -189,6 +184,11 @@ public function transformWithRoundingProvider()
189184
*/
190185
public function testTransformWithRounding($scale, $input, $output, $roundingMode)
191186
{
187+
// Since we test against "de_AT", we need the full implementation
188+
IntlTestHelper::requireFullIntl($this);
189+
190+
\Locale::setDefault('de_AT');
191+
192192
$transformer = new NumberToLocalizedStringTransformer($scale, null, $roundingMode);
193193

194194
$this->assertEquals($output, $transformer->transform($input));

Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,42 @@ public function testSubmitMultipleExpandedNumericChoices()
13371337
$this->assertNull($form[4]->getViewData());
13381338
}
13391339

1340+
public function testSingleSelectedObjectChoices()
1341+
{
1342+
$form = $this->factory->create('choice', $this->objectChoices[3], array(
1343+
'multiple' => false,
1344+
'expanded' => false,
1345+
'choices' => $this->objectChoices,
1346+
'choices_as_values' => true,
1347+
'choice_label' => 'name',
1348+
'choice_value' => 'id',
1349+
));
1350+
1351+
$view = $form->createView();
1352+
$selectedChecker = $view->vars['is_selected'];
1353+
1354+
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
1355+
$this->assertFalse($selectedChecker($view->vars['choices'][1]->value, $view->vars['value']));
1356+
}
1357+
1358+
public function testMultipleSelectedObjectChoices()
1359+
{
1360+
$form = $this->factory->create('choice', array($this->objectChoices[3]), array(
1361+
'multiple' => true,
1362+
'expanded' => false,
1363+
'choices' => $this->objectChoices,
1364+
'choices_as_values' => true,
1365+
'choice_label' => 'name',
1366+
'choice_value' => 'id',
1367+
));
1368+
1369+
$view = $form->createView();
1370+
$selectedChecker = $view->vars['is_selected'];
1371+
1372+
$this->assertTrue($selectedChecker($view->vars['choices'][3]->value, $view->vars['value']));
1373+
$this->assertFalse($selectedChecker($view->vars['choices'][1]->value, $view->vars['value']));
1374+
}
1375+
13401376
/*
13411377
* We need this functionality to create choice fields for Boolean types,
13421378
* e.g. false => 'No', true => 'Yes'

0 commit comments

Comments
 (0)