From 323dfa05cba9845a74f418ac9e1e14953a425028 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Fri, 23 Apr 2021 10:30:00 +0200 Subject: [PATCH 1/2] fix readability of test, no functional changes --- tests/helpers/RequestParserTest.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/helpers/RequestParserTest.php b/tests/helpers/RequestParserTest.php index de9288e..bd0b875 100644 --- a/tests/helpers/RequestParserTest.php +++ b/tests/helpers/RequestParserTest.php @@ -214,9 +214,22 @@ public function testHasIncludePaths() { } public function testGetIncludePaths_Reformatted() { - $queryParameters = ['include' => 'foo,bar,baz.baf']; + $paths = [ + 'foo', + 'bar', + 'baz.baf', + ]; + $expected = [ + 'foo' => [], + 'bar' => [], + 'baz' => [ + 'baf' => [], + ], + ]; + + $queryParameters = ['include' => implode(',', $paths)]; $requestParser = new RequestParser($selfLink='', $queryParameters); - $this->assertSame(['foo' => [], 'bar' => [], 'baz' => ['baf' => []]], $requestParser->getIncludePaths()); + $this->assertSame($expected, $requestParser->getIncludePaths()); } public function testGetIncludePaths_Raw() { From 4f314486f8183af4d0a15d278e298545004389b1 Mon Sep 17 00:00:00 2001 From: Lode Claassen Date: Fri, 23 Apr 2021 10:31:36 +0200 Subject: [PATCH 2/2] fix including multiple relationships from the same relationship path --- src/helpers/RequestParser.php | 2 +- tests/helpers/RequestParserTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/helpers/RequestParser.php b/src/helpers/RequestParser.php index f87e4c8..5ae8f25 100644 --- a/src/helpers/RequestParser.php +++ b/src/helpers/RequestParser.php @@ -144,7 +144,7 @@ public function getIncludePaths(array $options=[]) { $wrapped = [$lastStep => $wrapped]; } - $restructured = array_merge($restructured, $wrapped); + $restructured = array_merge_recursive($restructured, $wrapped); } return $restructured; diff --git a/tests/helpers/RequestParserTest.php b/tests/helpers/RequestParserTest.php index bd0b875..6410c78 100644 --- a/tests/helpers/RequestParserTest.php +++ b/tests/helpers/RequestParserTest.php @@ -218,12 +218,26 @@ public function testGetIncludePaths_Reformatted() { 'foo', 'bar', 'baz.baf', + 'baz.bat', + 'user.ship.wing', + 'user.ship.nose.window', + 'user.friends', ]; $expected = [ 'foo' => [], 'bar' => [], 'baz' => [ 'baf' => [], + 'bat' => [], + ], + 'user' => [ + 'ship' => [ + 'wing' => [], + 'nose' => [ + 'window' => [], + ], + ], + 'friends' => [], ], ];