NumericNodeDefinitionTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Tests\Definition\Builder;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\Builder\FloatNodeDefinition;
  13. use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
  14. use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition as NumericNodeDefinition;
  15. class NumericNodeDefinitionTest extends TestCase
  16. {
  17. /**
  18. * @expectedException \InvalidArgumentException
  19. * @expectedExceptionMessage You cannot define a min(4) as you already have a max(3)
  20. */
  21. public function testIncoherentMinAssertion()
  22. {
  23. $def = new NumericNodeDefinition('foo');
  24. $def->max(3)->min(4);
  25. }
  26. /**
  27. * @expectedException \InvalidArgumentException
  28. * @expectedExceptionMessage You cannot define a max(2) as you already have a min(3)
  29. */
  30. public function testIncoherentMaxAssertion()
  31. {
  32. $node = new NumericNodeDefinition('foo');
  33. $node->min(3)->max(2);
  34. }
  35. /**
  36. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  37. * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than or equal to 5
  38. */
  39. public function testIntegerMinAssertion()
  40. {
  41. $def = new IntegerNodeDefinition('foo');
  42. $def->min(5)->getNode()->finalize(4);
  43. }
  44. /**
  45. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  46. * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than or equal to 3
  47. */
  48. public function testIntegerMaxAssertion()
  49. {
  50. $def = new IntegerNodeDefinition('foo');
  51. $def->max(3)->getNode()->finalize(4);
  52. }
  53. public function testIntegerValidMinMaxAssertion()
  54. {
  55. $def = new IntegerNodeDefinition('foo');
  56. $node = $def->min(3)->max(7)->getNode();
  57. $this->assertEquals(4, $node->finalize(4));
  58. }
  59. /**
  60. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  61. * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than or equal to 500
  62. */
  63. public function testFloatMinAssertion()
  64. {
  65. $def = new FloatNodeDefinition('foo');
  66. $def->min(5E2)->getNode()->finalize(4e2);
  67. }
  68. /**
  69. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  70. * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than or equal to 0.3
  71. */
  72. public function testFloatMaxAssertion()
  73. {
  74. $def = new FloatNodeDefinition('foo');
  75. $def->max(0.3)->getNode()->finalize(4.3);
  76. }
  77. public function testFloatValidMinMaxAssertion()
  78. {
  79. $def = new FloatNodeDefinition('foo');
  80. $node = $def->min(3.0)->max(7e2)->getNode();
  81. $this->assertEquals(4.5, $node->finalize(4.5));
  82. }
  83. }