FloatNodeTest.php 1.5 KB

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