BooleanNodeTest.php 1.7 KB

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