Skip to content

Commit 8e4b808

Browse files
committed
Merge branch '2.1'
* 2.1: fixed CS added doc comments added doc comments [Validator] Updated swedish translation Update src/Symfony/Component/Validator/Resources/translations/validators.de.xlf [2.1] Exclude tests from zips via gitattributes [HttpKernel][Translator] Fixed type-hints Updated lithuanian validation translation [DomCrawler] Allows using multiselect through Form::setValues(). [Translation] forced the catalogue to be regenerated when a resource is added (closes symfony/translation#1) Unit test for patched method OptionsResolver::validateOptionValues(). validateOptionValues throw a notice if an allowed value is set and the corresponding option isn't. [Form] Hardened code of ViolationMapper against errors [HttpFoundation] Fixed #5611 - Request::splitHttpAcceptHeader incorrect result order. [Form] Fixed negative index access in PropertyPathBuilder Update src/Symfony/Component/Validator/Resources/translations/validators.ro.xlf Conflicts: src/Symfony/Component/DomCrawler/Form.php src/Symfony/Component/Process/Process.php
2 parents c1ac1d8 + 1ee199a commit 8e4b808

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Tests/ export-ignore
2+
phpunit.xml.dist export-ignore

OptionsResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ private function validateOptionsCompleteness(array $options)
294294
private function validateOptionValues(array $options)
295295
{
296296
foreach ($this->allowedValues as $option => $allowedValues) {
297-
if (!in_array($options[$option], $allowedValues, true)) {
297+
if (isset($options[$option]) && !in_array($options[$option], $allowedValues, true)) {
298298
throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", but is expected to be one of "%s"', $option, $options[$option], implode('", "', $allowedValues)));
299299
}
300300
}

Tests/OptionsResolverTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,30 @@ public function testResolveSucceedsIfOptionValueAllowed2()
258258
), $this->resolver->resolve($options));
259259
}
260260

261+
public function testResolveSucceedsIfOptionalWithAllowedValuesNotSet()
262+
{
263+
$this->resolver->setRequired(array(
264+
'one',
265+
));
266+
267+
$this->resolver->setOptional(array(
268+
'two',
269+
));
270+
271+
$this->resolver->setAllowedValues(array(
272+
'one' => array('1', 'one'),
273+
'two' => array('2', 'two'),
274+
));
275+
276+
$options = array(
277+
'one' => '1',
278+
);
279+
280+
$this->assertEquals(array(
281+
'one' => '1',
282+
), $this->resolver->resolve($options));
283+
}
284+
261285
/**
262286
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
263287
*/

0 commit comments

Comments
 (0)