diff --git a/src/Symfony/Component/DependencyInjection/Configuration/ScalarNode.php b/src/Symfony/Component/DependencyInjection/Configuration/ScalarNode.php index fd871c3864..3f270bf14c 100644 --- a/src/Symfony/Component/DependencyInjection/Configuration/ScalarNode.php +++ b/src/Symfony/Component/DependencyInjection/Configuration/ScalarNode.php @@ -8,6 +8,13 @@ use Symfony\Component\DependencyInjection\Configuration\Exception\InvalidTypeExc /** * This node represents a scalar value in the config tree. * + * The following values are considered scalars: + * * booleans + * * strings + * * null + * * integers + * * floats + * * @author Johannes M. Schmitt */ class ScalarNode extends BaseNode implements PrototypeNodeInterface @@ -44,7 +51,7 @@ class ScalarNode extends BaseNode implements PrototypeNodeInterface protected function validateType($value) { - if (!is_scalar($value)) { + if (!is_scalar($value) && null !== $value) { throw new InvalidTypeException(sprintf( 'Invalid type for path "%s". Expected scalar, but got %s.', $this->getPath(), diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Configuration/ScalarNodeTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Configuration/ScalarNodeTest.php new file mode 100644 index 0000000000..8ff43ca073 --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Configuration/ScalarNodeTest.php @@ -0,0 +1,49 @@ +assertSame($value, $node->normalize($value)); + } + + public function getValidValues() + { + return array( + array(false), + array(true), + array(null), + array(''), + array('foo'), + array(0), + array(1), + array(0.0), + array(0.1), + ); + } + + /** + * @dataProvider getInvalidValues + * @expectedException Symfony\Component\DependencyInjection\Configuration\Exception\InvalidTypeException + */ + public function testNormalizeThrowsExceptionOnInvalidValues($value) + { + $node = new ScalarNode('test'); + $node->normalize($value); + } + + public function getInvalidValues() + { + return array( + array(array()), + array(array('foo' => 'bar')), + array(new \stdClass()), + ); + } +} \ No newline at end of file