Skip to content

Commit

Permalink
fix 5528 let ArrayNode::normalizeValue respect order of value array p…
Browse files Browse the repository at this point in the history
…rovided
  • Loading branch information
cordoval authored and fabpot committed Dec 17, 2013
1 parent 8b7d0e8 commit bee06e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Expand Up @@ -303,9 +303,9 @@ protected function normalizeValue($value)
$value = $this->remapXml($value);

$normalized = array();
foreach ($this->children as $name => $child) {
if (array_key_exists($name, $value)) {
$normalized[$name] = $child->normalize($value[$name]);
foreach ($value as $name => $val) {
if (isset($this->children[$name])) {
$normalized[$name] = $this->children[$name]->normalize($val);
unset($value[$name]);
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php
Expand Up @@ -129,4 +129,33 @@ public function getZeroNamedNodeExamplesData()
),
);
}

/**
* @dataProvider getPreNormalizedNormalizedOrderedData
*/
public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $normalized)
{
$scalar1 = new ScalarNode('1');
$scalar2 = new ScalarNode('2');
$scalar3 = new ScalarNode('3');
$node = new ArrayNode('foo');
$node->addChild($scalar1);
$node->addChild($scalar3);
$node->addChild($scalar2);

$r = new \ReflectionMethod($node, 'normalizeValue');
$r->setAccessible(true);

$this->assertSame($normalized, $r->invoke($node, $prenormalized));
}

public function getPreNormalizedNormalizedOrderedData()
{
return array(
array(
array('2' => 'two', '1' => 'one', '3' => 'three'),
array('2' => 'two', '1' => 'one', '3' => 'three'),
),
);
}
}

0 comments on commit bee06e9

Please sign in to comment.