IntegerNodeTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\IntegerNode;
  12. class IntegerNodeTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getValidValues
  16. */
  17. public function testNormalize($value)
  18. {
  19. $node = new IntegerNode('test');
  20. $this->assertSame($value, $node->normalize($value));
  21. }
  22. public function getValidValues()
  23. {
  24. return array(
  25. array(1798),
  26. array(-678),
  27. array(0),
  28. );
  29. }
  30. /**
  31. * @dataProvider getInvalidValues
  32. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
  33. */
  34. public function testNormalizeThrowsExceptionOnInvalidValues($value)
  35. {
  36. $node = new IntegerNode('test');
  37. $node->normalize($value);
  38. }
  39. public function getInvalidValues()
  40. {
  41. return array(
  42. array(null),
  43. array(''),
  44. array('foo'),
  45. array(true),
  46. array(false),
  47. array(0.0),
  48. array(0.1),
  49. array(array()),
  50. array(array('foo' => 'bar')),
  51. array(new \stdClass()),
  52. );
  53. }
  54. }