Browse Source

[Config] Reverting some meaningless changes that are no longer needed to minimize the true diff of the changes. Increasing the test precision.

Ryan Weaver 14 năm trước cách đây
mục cha
commit
d2971e0f5f

+ 6 - 6
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;
     }
 
     /**

+ 12 - 3
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