FloatNodeTest.php 1.7 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 [
  37. [1798.0],
  38. [-678.987],
  39. [12.56E45],
  40. [0.0],
  41. // Integer are accepted too, they will be cast
  42. [17],
  43. [-10],
  44. [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 [
  59. [null],
  60. [''],
  61. ['foo'],
  62. [true],
  63. [false],
  64. [[]],
  65. [['foo' => 'bar']],
  66. [new \stdClass()],
  67. ];
  68. }
  69. }