diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 7c9c145943..3509d4712d 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -303,9 +303,8 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface if (isset($this->children[$name])) { $normalized[$name] = $this->children[$name]->normalize($val); unset($value[$name]); - } elseif (false === $this->removeExtraKeys) { + } elseif (!$this->removeExtraKeys) { $normalized[$name] = $val; - unset($value[$name]); } } diff --git a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php index c88fc13f07..4496b61fe4 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Tests\Definition; use Symfony\Component\Config\Definition\ArrayNode; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\ScalarNode; class ArrayNodeTest extends \PHPUnit_Framework_TestCase @@ -35,34 +36,30 @@ class ArrayNodeTest extends \PHPUnit_Framework_TestCase $node->normalize(array('foo' => 'bar')); } - /** - * Tests that no exception is thrown for an unrecognized child if the - * ignoreExtraKeys option is set to true. - * - * Related to testExceptionThrownOnUnrecognizedChild - */ - public function testIgnoreExtraKeysNoException() + public function ignoreAndRemoveMatrixProvider() { - $node = new ArrayNode('roo'); - $node->setIgnoreExtraKeys(true); + $unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"'); - $node->normalize(array('foo' => 'bar')); - $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true'); + return array( + array(true, true, array(), 'no exception is thrown for an unrecognized child if the ignoreExtraKeys option is set to true'), + array(true, false, array('foo' => 'bar'), 'extra keys are not removed when ignoreExtraKeys second option is set to false'), + array(false, true, $unrecognizedOptionException), + array(false, false, $unrecognizedOptionException), + ); } /** - * Tests that extra keys are not removed when - * ignoreExtraKeys second option is set to false. - * - * Related to testExceptionThrownOnUnrecognizedChild + * @dataProvider ignoreAndRemoveMatrixProvider */ - public function testIgnoreExtraKeysNotRemoved() + public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '') { - $node = new ArrayNode('roo'); - $node->setIgnoreExtraKeys(true, false); - - $data = array('foo' => 'bar'); - $this->assertSame($data, $node->normalize($data)); + if ($expected instanceof \Exception) { + $this->setExpectedException(get_class($expected), $expected->getMessage()); + } + $node = new ArrayNode('root'); + $node->setIgnoreExtraKeys($ignore, $remove); + $result = $node->normalize(array('foo' => 'bar')); + $this->assertSame($expected, $result, $message); } /**