BooleanNodeTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Tests\Component\Config\Definition;
  11. use Symfony\Component\Config\Definition\BooleanNode;
  12. class BooleanNodeTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @dataProvider getValidValues
  16. */
  17. public function testNormalize($value)
  18. {
  19. $node = new BooleanNode('test');
  20. $this->assertSame($value, $node->normalize($value));
  21. }
  22. public function getValidValues()
  23. {
  24. return array(
  25. array(false),
  26. array(true),
  27. );
  28. }
  29. /**
  30. * @dataProvider getInvalidValues
  31. * @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
  32. */
  33. public function testNormalizeThrowsExceptionOnInvalidValues($value)
  34. {
  35. $node = new BooleanNode('test');
  36. $node->normalize($value);
  37. }
  38. public function getInvalidValues()
  39. {
  40. return array(
  41. array(null),
  42. array(''),
  43. array('foo'),
  44. array(0),
  45. array(1),
  46. array(0.0),
  47. array(0.1),
  48. array(array()),
  49. array(array('foo' => 'bar')),
  50. array(new \stdClass()),
  51. );
  52. }
  53. }