IntegerNodeTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\IntegerNode;
  13. class IntegerNodeTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider getValidValues
  17. */
  18. public function testNormalize($value)
  19. {
  20. $node = new IntegerNode('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 IntegerNode('test');
  31. $node->setAllowEmptyValue(false);
  32. $this->assertSame($value, $node->finalize($value));
  33. }
  34. public function getValidValues()
  35. {
  36. return array(
  37. array(1798),
  38. array(-678),
  39. array(0),
  40. );
  41. }
  42. /**
  43. * @dataProvider getInvalidValues
  44. * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
  45. */
  46. public function testNormalizeThrowsExceptionOnInvalidValues($value)
  47. {
  48. $node = new IntegerNode('test');
  49. $node->normalize($value);
  50. }
  51. public function getInvalidValues()
  52. {
  53. return array(
  54. array(null),
  55. array(''),
  56. array('foo'),
  57. array(true),
  58. array(false),
  59. array(0.0),
  60. array(0.1),
  61. array(array()),
  62. array(array('foo' => 'bar')),
  63. array(new \stdClass()),
  64. );
  65. }
  66. }