fix handling float-like key attribute values
This commit is contained in:
parent
3ee310f20a
commit
a2ad4fa8b3
@ -237,6 +237,10 @@ class PrototypedArrayNode extends ArrayNode
|
|||||||
} elseif (isset($v[$this->keyAttribute])) {
|
} elseif (isset($v[$this->keyAttribute])) {
|
||||||
$k = $v[$this->keyAttribute];
|
$k = $v[$this->keyAttribute];
|
||||||
|
|
||||||
|
if (\is_float($k)) {
|
||||||
|
$k = var_export($k, true);
|
||||||
|
}
|
||||||
|
|
||||||
// remove the key attribute when required
|
// remove the key attribute when required
|
||||||
if ($this->removeKeyAttribute) {
|
if ($this->removeKeyAttribute) {
|
||||||
unset($v[$this->keyAttribute]);
|
unset($v[$this->keyAttribute]);
|
||||||
|
@ -201,6 +201,32 @@ class NormalizationTest extends TestCase
|
|||||||
$this->assertNormalized($tree, $data, $data);
|
$this->assertNormalized($tree, $data, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFloatLikeValueAsMapKeyAttribute()
|
||||||
|
{
|
||||||
|
$tree = (new TreeBuilder('root'))
|
||||||
|
->getRootNode()
|
||||||
|
->useAttributeAsKey('number')
|
||||||
|
->arrayPrototype()
|
||||||
|
->children()
|
||||||
|
->scalarNode('foo')->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->buildTree()
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertNormalized($tree, [
|
||||||
|
[
|
||||||
|
'number' => 3.0,
|
||||||
|
'foo' => 'bar',
|
||||||
|
],
|
||||||
|
], [
|
||||||
|
'3.0' => [
|
||||||
|
'foo' => 'bar',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
|
public static function assertNormalized(NodeInterface $tree, $denormalized, $normalized)
|
||||||
{
|
{
|
||||||
self::assertSame($normalized, $tree->normalize($denormalized));
|
self::assertSame($normalized, $tree->normalize($denormalized));
|
||||||
|
Reference in New Issue
Block a user