Skip to content

Commit 1007c39

Browse files
Merge branch '2.3' into 2.7
* 2.3: Fix security-acl deps Fix doctrine mapping validation type error Remove skipping of tests based on ICU data version whenever possible Fix the handling of null as locale in the stub intl classes do not dump leading backslashes in class names Skip ::class constant [Config] type specific check for emptiness Conflicts: src/Symfony/Bridge/Twig/composer.json src/Symfony/Bundle/SecurityBundle/composer.json src/Symfony/Component/Config/Tests/Definition/ScalarNodeTest.php src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php src/Symfony/Component/Locale/Tests/LocaleTest.php src/Symfony/Component/Locale/Tests/Stub/StubLocaleTest.php src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php
2 parents 65791be + 0c71f0b commit 1007c39

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

Definition/BooleanNode.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,13 @@ protected function validateType($value)
3939
throw $ex;
4040
}
4141
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
protected function isValueEmpty($value)
47+
{
48+
// a boolean value cannot be empty
49+
return false;
50+
}
4251
}

Definition/NumericNode.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,13 @@ protected function finalizeValue($value)
5252

5353
return $value;
5454
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
protected function isValueEmpty($value)
60+
{
61+
// a numeric value cannot be empty
62+
return false;
63+
}
5564
}

Definition/ScalarNode.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ protected function validateType($value)
4646
throw $ex;
4747
}
4848
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
protected function isValueEmpty($value)
54+
{
55+
return null === $value || '' === $value;
56+
}
4957
}

Definition/VariableNode.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function validateType($value)
8484
*/
8585
protected function finalizeValue($value)
8686
{
87-
if (!$this->allowEmptyValue && empty($value)) {
87+
if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
8888
$ex = new InvalidConfigurationException(sprintf(
8989
'The path "%s" cannot contain an empty value, but got %s.',
9090
$this->getPath(),
@@ -116,4 +116,20 @@ protected function mergeValues($leftSide, $rightSide)
116116
{
117117
return $rightSide;
118118
}
119+
120+
/**
121+
* Evaluates if the given value is to be treated as empty.
122+
*
123+
* By default, PHP's empty() function is used to test for emptiness. This
124+
* method may be overridden by subtypes to better match their understanding
125+
* of empty data.
126+
*
127+
* @param mixed $value
128+
*
129+
* @return bool
130+
*/
131+
protected function isValueEmpty($value)
132+
{
133+
return empty($value);
134+
}
119135
}

Tests/Definition/BooleanNodeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function testNormalize($value)
2424
$this->assertSame($value, $node->normalize($value));
2525
}
2626

27+
/**
28+
* @dataProvider getValidValues
29+
*
30+
* @param bool $value
31+
*/
32+
public function testValidNonEmptyValues($value)
33+
{
34+
$node = new BooleanNode('test');
35+
$node->setAllowEmptyValue(false);
36+
37+
$this->assertSame($value, $node->finalize($value));
38+
}
39+
2740
public function getValidValues()
2841
{
2942
return array(

Tests/Definition/FloatNodeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function testNormalize($value)
2424
$this->assertSame($value, $node->normalize($value));
2525
}
2626

27+
/**
28+
* @dataProvider getValidValues
29+
*
30+
* @param int $value
31+
*/
32+
public function testValidNonEmptyValues($value)
33+
{
34+
$node = new FloatNode('test');
35+
$node->setAllowEmptyValue(false);
36+
37+
$this->assertSame($value, $node->finalize($value));
38+
}
39+
2740
public function getValidValues()
2841
{
2942
return array(

Tests/Definition/IntegerNodeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function testNormalize($value)
2424
$this->assertSame($value, $node->normalize($value));
2525
}
2626

27+
/**
28+
* @dataProvider getValidValues
29+
*
30+
* @param int $value
31+
*/
32+
public function testValidNonEmptyValues($value)
33+
{
34+
$node = new IntegerNode('test');
35+
$node->setAllowEmptyValue(false);
36+
37+
$this->assertSame($value, $node->finalize($value));
38+
}
39+
2740
public function getValidValues()
2841
{
2942
return array(

Tests/Definition/ScalarNodeTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,51 @@ public function testNormalizeThrowsExceptionWithErrorMessage()
7676

7777
$node->normalize(array());
7878
}
79+
80+
/**
81+
* @dataProvider getValidNonEmptyValues
82+
*
83+
* @param mixed $value
84+
*/
85+
public function testValidNonEmptyValues($value)
86+
{
87+
$node = new ScalarNode('test');
88+
$node->setAllowEmptyValue(false);
89+
90+
$this->assertSame($value, $node->finalize($value));
91+
}
92+
93+
public function getValidNonEmptyValues()
94+
{
95+
return array(
96+
array(false),
97+
array(true),
98+
array('foo'),
99+
array(0),
100+
array(1),
101+
array(0.0),
102+
array(0.1),
103+
);
104+
}
105+
106+
/**
107+
* @dataProvider getEmptyValues
108+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
109+
*
110+
* @param mixed $value
111+
*/
112+
public function testNotAllowedEmptyValuesThrowException($value)
113+
{
114+
$node = new ScalarNode('test');
115+
$node->setAllowEmptyValue(false);
116+
$node->finalize($value);
117+
}
118+
119+
public function getEmptyValues()
120+
{
121+
return array(
122+
array(null),
123+
array(''),
124+
);
125+
}
79126
}

0 commit comments

Comments
 (0)