IntegerNodeTest.php 1.6 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 [
  37. [1798],
  38. [-678],
  39. [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 [
  54. [null],
  55. [''],
  56. ['foo'],
  57. [true],
  58. [false],
  59. [0.0],
  60. [0.1],
  61. [[]],
  62. [['foo' => 'bar']],
  63. [new \stdClass()],
  64. ];
  65. }
  66. }