ArrayNodeTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\ArrayNode;
  12. class ArrayNodeTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @expectedException Symfony\Component\Config\Definition\Exception\InvalidTypeException
  16. */
  17. public function testNormalizeThrowsExceptionWhenFalseIsNotAllowed()
  18. {
  19. $node = new ArrayNode('root');
  20. $node->normalize(false);
  21. }
  22. /**
  23. * normalize() should protect against child values with no corresponding node
  24. */
  25. public function testExceptionThrownOnUnrecognizedChild()
  26. {
  27. $node = new ArrayNode('root');
  28. try
  29. {
  30. $node->normalize(array('foo' => 'bar'));
  31. $this->fail('An exception should have been throw for a bad child node');
  32. } catch (\Exception $e) {
  33. $this->assertInstanceOf('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', $e);
  34. $this->assertEquals('Unrecognized options "foo" under "root"', $e->getMessage());
  35. }
  36. }
  37. /**
  38. * Tests that no exception is thrown for an unrecognized child if the
  39. * ignoreExtraKeys option is set to true.
  40. *
  41. * Related to testExceptionThrownOnUnrecognizedChild
  42. */
  43. public function testIgnoreExtraKeysNoException()
  44. {
  45. $node = new ArrayNode('roo');
  46. $node->setIgnoreExtraKeys(true);
  47. $node->normalize(array('foo' => 'bar'));
  48. $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
  49. }
  50. }