Yaffs site version 1.1
[yaffs-website] / vendor / symfony / config / Tests / Definition / Builder / NumericNodeDefinitionTest.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\Builder;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition as NumericNodeDefinition;
16 use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
17 use Symfony\Component\Config\Definition\Builder\FloatNodeDefinition;
18
19 class NumericNodeDefinitionTest extends TestCase
20 {
21     /**
22      * @expectedException \InvalidArgumentException
23      * @expectedExceptionMessage You cannot define a min(4) as you already have a max(3)
24      */
25     public function testIncoherentMinAssertion()
26     {
27         $def = new NumericNodeDefinition('foo');
28         $def->max(3)->min(4);
29     }
30
31     /**
32      * @expectedException \InvalidArgumentException
33      * @expectedExceptionMessage You cannot define a max(2) as you already have a min(3)
34      */
35     public function testIncoherentMaxAssertion()
36     {
37         $node = new NumericNodeDefinition('foo');
38         $node->min(3)->max(2);
39     }
40
41     /**
42      * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
43      * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than or equal to 5
44      */
45     public function testIntegerMinAssertion()
46     {
47         $def = new IntegerNodeDefinition('foo');
48         $def->min(5)->getNode()->finalize(4);
49     }
50
51     /**
52      * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
53      * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than or equal to 3
54      */
55     public function testIntegerMaxAssertion()
56     {
57         $def = new IntegerNodeDefinition('foo');
58         $def->max(3)->getNode()->finalize(4);
59     }
60
61     public function testIntegerValidMinMaxAssertion()
62     {
63         $def = new IntegerNodeDefinition('foo');
64         $node = $def->min(3)->max(7)->getNode();
65         $this->assertEquals(4, $node->finalize(4));
66     }
67
68     /**
69      * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
70      * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than or equal to 500
71      */
72     public function testFloatMinAssertion()
73     {
74         $def = new FloatNodeDefinition('foo');
75         $def->min(5E2)->getNode()->finalize(4e2);
76     }
77
78     /**
79      * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
80      * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than or equal to 0.3
81      */
82     public function testFloatMaxAssertion()
83     {
84         $def = new FloatNodeDefinition('foo');
85         $def->max(0.3)->getNode()->finalize(4.3);
86     }
87
88     public function testFloatValidMinMaxAssertion()
89     {
90         $def = new FloatNodeDefinition('foo');
91         $node = $def->min(3.0)->max(7e2)->getNode();
92         $this->assertEquals(4.5, $node->finalize(4.5));
93     }
94 }