FloatNodeTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Definition\FloatNode;
  13. class FloatNodeTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider getValidValues
  17. */
  18. public function testNormalize($value)
  19. {
  20. $node = new FloatNode('test');
  21. $this->assertSame($value, $node->normalize($value));
  22. }
  23. /**
  24. * @dataProvider getValidValues
  25. *
  26. * @param int $value
  27. */
  28. public function testValidNonEmptyValues($value)
  29. {
  30. $node = new FloatNode('test');
  31. $node->setAllowEmptyValue(false);
  32. $this->assertSame($value, $node->finalize($value));
  33. }
  34. public function getValidValues()
  35. {
  36. return array(
  37. array(1798.0),
  38. array(-678.987),
  39. array(12.56E45),
  40. array(0.0),
  41. // Integer are accepted too, they will be cast
  42. array(17),
  43. array(-10),
  44. array(0),
  45. );
  46. }
  47. /**
  48. * @dataProvider getInvalidValues
  49. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
  50. */
  51. public function testNormalizeThrowsExceptionOnInvalidValues($value)
  52. {
  53. $node = new FloatNode('test');
  54. $node->normalize($value);
  55. }
  56. public function getInvalidValues()
  57. {
  58. return array(
  59. array(null),
  60. array(''),
  61. array('foo'),
  62. array(true),
  63. array(false),
  64. array(array()),
  65. array(array('foo' => 'bar')),
  66. array(new \stdClass()),
  67. );
  68. }
  69. }