ArrayNodeTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $node->normalize(array('foo' => 'bar'));
  30. $this->fail('An exception should have been throw for a bad child node');
  31. } catch (\Exception $e) {
  32. $this->assertInstanceOf('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', $e);
  33. $this->assertEquals('Unrecognized options "foo" under "root"', $e->getMessage());
  34. }
  35. }
  36. /**
  37. * Tests that no exception is thrown for an unrecognized child if the
  38. * ignoreExtraKeys option is set to true.
  39. *
  40. * Related to testExceptionThrownOnUnrecognizedChild
  41. */
  42. public function testIgnoreExtraKeysNoException()
  43. {
  44. $node = new ArrayNode('roo');
  45. $node->setIgnoreExtraKeys(true);
  46. $node->normalize(array('foo' => 'bar'));
  47. $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
  48. }
  49. }