ArrayNodeTest.php 1.5 KB

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