4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Config\Tests\Definition;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\ScalarNode;
17 class ScalarNodeTest extends TestCase
20 * @dataProvider getValidValues
22 public function testNormalize($value)
24 $node = new ScalarNode('test');
25 $this->assertSame($value, $node->normalize($value));
28 public function getValidValues()
44 * @dataProvider getInvalidValues
45 * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
47 public function testNormalizeThrowsExceptionOnInvalidValues($value)
49 $node = new ScalarNode('test');
50 $node->normalize($value);
53 public function getInvalidValues()
57 array(array('foo' => 'bar')),
58 array(new \stdClass()),
62 public function testNormalizeThrowsExceptionWithoutHint()
64 $node = new ScalarNode('test');
66 if (method_exists($this, 'expectException')) {
67 $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
68 $this->expectExceptionMessage('Invalid type for path "test". Expected scalar, but got array.');
70 $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', 'Invalid type for path "test". Expected scalar, but got array.');
73 $node->normalize(array());
76 public function testNormalizeThrowsExceptionWithErrorMessage()
78 $node = new ScalarNode('test');
79 $node->setInfo('"the test value"');
81 if (method_exists($this, 'expectException')) {
82 $this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
83 $this->expectExceptionMessage("Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
85 $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException', "Invalid type for path \"test\". Expected scalar, but got array.\nHint: \"the test value\"");
88 $node->normalize(array());
92 * @dataProvider getValidNonEmptyValues
96 public function testValidNonEmptyValues($value)
98 $node = new ScalarNode('test');
99 $node->setAllowEmptyValue(false);
101 $this->assertSame($value, $node->finalize($value));
104 public function getValidNonEmptyValues()
118 * @dataProvider getEmptyValues
119 * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
121 * @param mixed $value
123 public function testNotAllowedEmptyValuesThrowException($value)
125 $node = new ScalarNode('test');
126 $node->setAllowEmptyValue(false);
127 $node->finalize($value);
130 public function getEmptyValues()