From 951385cf8ad15618820f02e0b5aed0db31638e9c Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Mon, 26 Feb 2018 13:25:04 -0500 Subject: [PATCH] correctly handle nested structs --- src/Core/GrpcTrait.php | 2 +- tests/unit/Core/GrpcTraitTest.php | 57 +++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/Core/GrpcTrait.php b/src/Core/GrpcTrait.php index e92496868286..d453f3e7865c 100644 --- a/src/Core/GrpcTrait.php +++ b/src/Core/GrpcTrait.php @@ -169,7 +169,7 @@ private function unpackValue($value) } return $valueList; case 'structValue': - return $this->unpackStructFromApi($setValue['structValue']); + return $this->unpackStructFromApi($value['structValue']); default: return $setValue; } diff --git a/tests/unit/Core/GrpcTraitTest.php b/tests/unit/Core/GrpcTraitTest.php index 36c8214cccda..4d04325f7cc7 100644 --- a/tests/unit/Core/GrpcTraitTest.php +++ b/tests/unit/Core/GrpcTraitTest.php @@ -270,14 +270,14 @@ public function timestampProvider() } /** - * @dataProvider valueProvider + * @dataProvider formatValueProvider */ public function testFormatsValue($value, $expected) { $this->assertEquals($expected, $this->implementation->call('formatValueForApi', [$value])); } - public function valueProvider() + public function formatValueProvider() { return [ ['string', ['string_value' => 'string']], @@ -309,4 +309,57 @@ public function valueProvider() ] ]; } + + /** + * @dataProvider unpackValueProvider + */ + public function testUnpackValue($expected, $value) + { + $this->assertEquals($expected, $this->implementation->call('unpackValue', [$value])); + } + + public function unpackValueProvider() + { + return [ + ['string', ['stringValue' => 'string']], + [ + ['1'], + [ + 'listValue' => [ + 'values' => [ + [ + 'stringValue' => '1' + ] + ] + ] + ] + ], + [ + [ + 'test' =>'test', + 'nested' => [ + 'test' => 'test' + ] + ], + [ + 'structValue' => [ + 'fields' => [ + 'test' => [ + 'stringValue' => 'test' + ], + 'nested' => [ + 'structValue' => [ + 'fields' => [ + 'test' => [ + 'stringValue' => 'test' + ] + ] + ] + ] + ] + ] + ] + ] + ]; + } }