ScalarNodeTest.php 1.4 KB

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