From d2971e0f5f2a3eb90d4fe3dfe77a18ede4d7abf1 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 18 Feb 2011 13:08:53 -0600 Subject: [PATCH] [Config] Reverting some meaningless changes that are no longer needed to minimize the true diff of the changes. Increasing the test precision. --- .../Component/Config/Definition/ArrayNode.php | 12 ++++++------ .../Component/Config/Definition/ArrayNodeTest.php | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 99e4f0f41a..122fee0cc1 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -405,24 +405,24 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface return $normalized; } - // note that this purposefully does not exclude unrecognized child keys. - // unrecognized keys are just added in - validation takes place in finalize + $normalized = array(); foreach ($this->children as $name => $child) { if (!array_key_exists($name, $value)) { continue; } - $value[$name] = $child->normalize($value[$name]); + $normalized[$name] = $child->normalize($value[$name]); + unset($value[$name]); } // if extra fields are present, throw exception - if ($diff = array_diff(array_keys($value), array_keys($this->children))) { - $msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', $diff), $this->getPath()); + if (count($value)) { + $msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath()); throw new InvalidConfigurationException($msg); } - return $value; + return $normalized; } /** diff --git a/tests/Symfony/Tests/Component/Config/Definition/ArrayNodeTest.php b/tests/Symfony/Tests/Component/Config/Definition/ArrayNodeTest.php index 4676a06da7..05f7de9030 100644 --- a/tests/Symfony/Tests/Component/Config/Definition/ArrayNodeTest.php +++ b/tests/Symfony/Tests/Component/Config/Definition/ArrayNodeTest.php @@ -51,12 +51,21 @@ class ArrayNodeTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array ('test'), $node->getDefaultValue()); } - // finalizeValue() should protect against child values with no corresponding node + /** + * normalize() should protect against child values with no corresponding node + */ public function testExceptionThrownOnUnrecognizedChild() { - $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException'); $node = new ArrayNode('root'); - $node->normalize(array('foo' => 'bar')); + + try + { + $node->normalize(array('foo' => 'bar')); + $this->fail('An exception should have been throw for a bad child node'); + } catch (\Exception $e) { + $this->assertInstanceOf('Symfony\Component\Config\Definition\Exception\InvalidConfigurationException', $e); + $this->assertEquals('Unrecognized options "foo" under "root"', $e->getMessage()); + } } // a remapped key (e.g. "mapping" -> "mappings") should be unset after being used