Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / Definition / FloatNodeTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Config\Tests\Definition;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\FloatNode;
16
17 class FloatNodeTest extends TestCase
18 {
19     /**
20      * @dataProvider getValidValues
21      */
22     public function testNormalize($value)
23     {
24         $node = new FloatNode('test');
25         $this->assertSame($value, $node->normalize($value));
26     }
27
28     /**
29      * @dataProvider getValidValues
30      *
31      * @param int $value
32      */
33     public function testValidNonEmptyValues($value)
34     {
35         $node = new FloatNode('test');
36         $node->setAllowEmptyValue(false);
37
38         $this->assertSame($value, $node->finalize($value));
39     }
40
41     public function getValidValues()
42     {
43         return array(
44             array(1798.0),
45             array(-678.987),
46             array(12.56E45),
47             array(0.0),
48             // Integer are accepted too, they will be cast
49             array(17),
50             array(-10),
51             array(0),
52         );
53     }
54
55     /**
56      * @dataProvider getInvalidValues
57      * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
58      */
59     public function testNormalizeThrowsExceptionOnInvalidValues($value)
60     {
61         $node = new FloatNode('test');
62         $node->normalize($value);
63     }
64
65     public function getInvalidValues()
66     {
67         return array(
68             array(null),
69             array(''),
70             array('foo'),
71             array(true),
72             array(false),
73             array(array()),
74             array(array('foo' => 'bar')),
75             array(new \stdClass()),
76         );
77     }
78 }